Page 74 - Modular v1.1 Pyhton
P. 74

OPERATIONS ON A LIST

                  There are several operations which can be performed on on the list. The following table describes
                  the various list operations.
                       Operator        Operations                             Explanation

                           +        Joining lists      To add/concatenate two list together by using ‘+’ operator.
                           *        Repeating lists    To multiplies a list by an integer ‘n’ and then creates a
                                                       new list which repeats the original list ‘n’ times by using’*’
                                                       operator.

                            :       Slicing lists      To access the list elements within a specific range.
                          = =       Comparing list     Check if the contents of the list are same or not by using
                                                       ‘==’ operator.

                  Program 5: Operations on a list.















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



















                      LIST METHODS

                  To make the use of list easier Python provides various built-in methods. In the above section
                  we have already discussed append( ) and extend( ) methods, let’s explore more methods. The
                  following table describes the various built-in methods.

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

                        extend( )    Add more than one elements to the end of the existing list
                        insert(x, a) Insert element ‘a’ at the ‘x’ location of the list

                        remove( )  Remove first element from the list


                   72     Touchpad MODULAR (Version 1.0)
   69   70   71   72   73   74   75   76   77   78   79