Page 152 - 2620_Birla Open Mind C-8
P. 152

Output

                [1, 2, 3, 5]
                [1, 2, 3, 5]
                []




                       Factbot


                The ‘+’ operator when used with lists needs both the operands to be of list type, otherwise it will produce
                an error.




                       Double Tap                                                  Century   #Information Literacy
                                                                                     21 st
                                                                                     Skills
                     Match the methods with their functionality.

                     1. extend( )               a. Removes the first occurrence of a specified element from a list.
                     2. append( )               b. Reverses the order of the elements in the list

                     3. remove( )               c. Adds single element at the end of the existing list

                     4. sort( )                 d.  Returns the occurrence (number of times) of a particular element in
                                                   the list
                     5. reverse( )              e. Sorts all the elements in the list

                     6. count( )                f.  Adds more than one element (in sequential order or elements of the
                                                  list) to the end of the existing list



                   PYTHON FUNCTIONS

              Python also provides various built-in Python list functions. The following table describes various Python
              built-in functions:

                             Function                               Explanation
                          len(list)        Returns the total length of the list
                          max(list)        Returns the largest element from the given list
                          min(list)        Returns the smallest element from the given list

              Program 10: To use the built-in Python list functions

                   Program10.py
                File  Edit  Format   Run   Options   Window    Help

                list1=[13, 25, 41, 63, 82]
                print(len(list1))
                print(max(list1))
                print(min(list1))






                  150  Premium Edition-VIII
   147   148   149   150   151   152   153   154   155   156   157