Page 158 - Plus_V2.2_C8_Flipbook
P. 158

Method           Explanation
                   append( )        Adds the element at the end of the existing list .

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

                   insert(x, a)     Inserts element ‘a’ at the ‘x’ location of the list.

                   remove(a)        Removes the first occurrence of 'a' from the list.

                   index(a)         Returns the index of the first occurrence of 'a' from the list.
                   count(a)         Returns the count of occurrence (number of times) of a particular element (a) in
                                    the list.

                   pop(i)           Removes and returns item at the ‘i’ location in the list.

                   copy( )          Returns a copy of the list.
                   clear( )         Removes all the elements from the list and returns an empty list.

                   sort( )          Sorts all the elements in the list.

                   reverse( )       Reverses the order of the elements in the list.



                   Program 15: To use the built-in methods on the list.

























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


















                  156   Premium Edition-VIII
   153   154   155   156   157   158   159   160   161   162   163