Page 90 - Modular v1.1 Pyhton
P. 90

Program 13: A tuple “tup” stores (2,5,7,8,2,1) by mistake its last element is typed wrong.

                  Write a program to correct its last element as 11.












                  On running the above program, you will get the following output:
















                     Recap


                           A tuple is a collection of objects which is immutable (non-modifiable).
                           Traversing means accessing or visiting the elements of a tuple.
                           Various ways to traverse a list are indexing, negative indexing and Tuple slicing.
                           The index of a tuple starts from 0.
                           The index -1 refers to the last element, -2 indexes refers to the second last element, and so on.
                           The slicing operator [:] is used to access the certain range of tuple elements.
                            Elements of a tuple cannot deleted or removed, but we can delete the entire tuple by using the
                           del keyword.
                           Entire tuple can be printed by just using the name of the tuple.




                                                         Exercise



                  A.  Tick ( ) the correct option.
                      1.   Which of the following statement defines the Tuple?
                           a.   A tuple is a collection of objects which is immutable

                           b.   Tuples are used to store multiple items in a single variable
                           c.   Tuples are written with round brackets ( ) and its indices start at 0
                           d.   All of the above

                      2.   Which of the following statement is correct to declare a Tuple with one item?
                           a.   tup1= (6,)                               b.   tup1 = (46;)
                           c.   tup1= (56:)                              d.   All of the above


                   88     Touchpad MODULAR (Version 1.0)
   85   86   87   88   89   90   91   92   93   94   95