Page 79 - Code & Click - 8
P. 79

2. Press the F5 key to execute the code. Sample output of the program is given below.















            List Functions
            Python provides several functions to work with lists. Some of these functions are described below:
               •  append( ): It is used to add an element at the end of a list. Its syntax is:
                  <list name>.append(value)
               •  extend( ): It is used to add more than one element at the end of a list. Its syntax is:
                  <list name>.extend(list of values)
               •  pop( ): It is used to delete an element from a list using its index. Its syntax is:
                  <list name>.pop(index)

                                                                                                 Experiential Learning
              Lab Activity 7
             To create a list with values accepted from the user and display the elements in the list.
             1. Type the code as shown in the image in the Python Editor.










             2. Press the F5 key to execute the code. Sample output of the program is given below.















                                                                                                 Experiential Learning
              Lab Activity 8
             To delete an element from a list.
             1. Type the code as shown in the image in the Python Editor.













                                                                                                                 77
   74   75   76   77   78   79   80   81   82   83   84