Basic HTML Version

|  | Table of Contents |  | View Full Version

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

    Output

                      5

                      82
                      13

                          OPERATIONS ON A LIST

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

                      Operator     Operations                                 Explanation

                           +       Joining lists  To add/concatenate two lists together by using the ‘+’ operator

                                                  It multiplies a list by an integer ‘n’ and then creates a new list which repeats
                           *       Repeating lists
                                                  the original list ‘n’ times by using the ‘*’ operator

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

                     Program 11: To perform the operations on the list
                         Program11.py

                      File  Edit  Format   Run   Options   Window     Help

                      list1=[13, 25, 41, 63, 82]

                      list2=[23, 35, 51, 73, 92]

                      print(list1+list2)
                      print(list1*4)
                      print(list1[0:4])
                      print(list1==list2)

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

                         Output

                      [13, 25, 41, 63, 82, 23, 35, 51, 73, 92]
                      [13, 25, 41, 63, 82, 13, 25, 41, 63, 82, 13, 25, 41, 63, 82, 13, 25, 41, 63, 82]
                      [13, 25, 41, 63]

                      False

                                                                                                         #List in Python 151

| 148 149 150 151 152 153 154 155 156 157 158 |