Wednesday, 16 June 2021

CLASS 11 CS CHAPTER 8

 

CLASS -11  COMPUTER  SCIENCE

                 CHAPTER- 8 TUPLE MANIPULATION


🔔To download textbook pdf click on the ''DOWNLOAD'' button below -



NOTES FOR COMPLETE UNDERSTANDING -


  • Tuple is also like list  which too can store list of any kind of values.

  • It is an immutable data type thus we can not change any value of tuple.

  • It is a sequence like string and list but the difference is that list is mutable whereas string and tuple are immutable.

  • Creation of a Tuple :
  • “( )” parenthesis are used for creation of tuple . 
  • ( )  ---> empty tuple 
  • ( 8, 2, 6)  ---> integers tuple
  • ( 1, 2.5, 3.7, 7)  ---> numbers tuple 
  • (‘p’, ’q’, ’r’ )   ----> characters tuple 
  • ( ‘p’, 1, ‘b’, 3.5, ‘hi’)  ----> mixed values tuple  
  • (‘one’, ’two’, ’three’, ’four’)  --->  string tuple                                                                                                                                                                                                     
  • Accessing a Tuple  :
  • The process of  accessing tuple elements is same as that with list. 
  • Like a list, we can access each and every element of a tuple using for loop. 

  • Like list, tuple also have index. A list and a tuple is same in every way except mutability.

  •  len ( ) function of python can be used to get the length of tuple.

  • Indexing and Slicing:
  • T[ p ] returns the item present at index p .
  • T[ p : j ] returns a new tuple having all the items of T from index p to j. 
  • T [ p : j : n ] returns a new tuple having difference of n elements of T from index p to j .

  • Membership operator:
  • Membership operator  “in”  and  “not in”  works similarly as in a list. 

  • Concatenation and Replication operators:
  • + operator adds 2nd tuple at the end of  1st tuple. This process is called concatenation .                    
  • * operator repeats elements of tuple . This process is called replication.                              

  • Tuple joining :                                                                                                                    ***Both the tuples should be there to add with +. 
  • There will occur error when below operations are processed-
  • Tuple + number 
  • Tuple + complex number 
  • Tuple + string
  • Tuple + list
  • Tuple + (5) will also generate error because when adding a tuple with a single value, tuple will also be considered as a value and not a tuple .To avoid this we would need to give command   >>> tuple +(5,)

  • Tuple Replication:                                                                                                              ***A Tuple and a number must be given.

  • Tuple Deletion :
  • Since tuple is  immutable data  type, it is not possible to delete an individual element of a tuple. With del( ) function, it is possible to delete a complete tuple.

  • Tuple ( ) Functions  -- This function converts a data type into Tuple data type.

  • len( ) Function  -- This function returns length of the tuple.

  • max( ) Function  -- This function returns maximum value in the tuple .

  • min( ) Function  -- This function returns minimum value in the tuple .

  • index( ) Function  -- This function returns the index of the element in the tuple .

            🔔MORE MATERIALS TO BE UPLOADED STAY TUNED🔔

WHY Software Developer ?