Page 86 - Modular v1.1 Pyhton
P. 86

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




















                      PYTHON TUPLE METHODS

                  As you know tuples are immutable. So, add and remove methods are not provided with tuples.
                  There are only two methods for tuples, which are described in the table given below.


                                   Method                                   Explanation
                          count(a)                     It returns number of times ‘a’ occurs in the tuple

                          index(a)                     It returns index of first element in tuple


                      PYTHON FUNCTIONS

                  Python also provides various built-in Python tuple functions. The table given below describes the
                  various built-in functions.

                                  Function                                 Explanation

                          len( )                      Returns the total length of the tuple

                          max( )                      Returns the largest element of the tuple
                          min( )                      Returns the smallest element of the tuple

                          sum( )                      Returns the sum of all the elements of the tuple
                          sorted()                    Returns the sorted list of elements

                          enumerate( )                Returns the enumerate object
                          all( )                      Returns true if all the elements of the tuple are true

                  Program 7: Functions on a tuple.

















                   84     Touchpad MODULAR (Version 1.0)
   81   82   83   84   85   86   87   88   89   90   91