Basic HTML Version

|  | Table of Contents |  | View Full Version

Page 93 - 2607_Traclpad_Pro_5.1_flipbook_C8
P. 93

    Output
                       [1, 2, 3, 4, 5, 6, 7, 8, 9]

                      The del Keyword
                      We use the del keyword to remove a sublist (start : stop : step) or a whole list of elements. Syntax

                      for using del keyword is:

                          del list_name(start : stop : step)
                      Program 18: To delete elements from the list.

                          Program18.py
                       File  Edit  Format    Run   Options   Window    Help
                       a=[1,2,3,4,5,6,7]

                       del a[1:3:2]
                       print (a)

                          Output
                       [1, 3, 4, 5, 6, 7]

                      Program 19: To delete the whole list.

                          Program19.py
                       File  Edit  Format    Run   Options   Window    Help

                       a=[1,2,3,4,5,6,7]
                       del a

                      The whole list will be deleted.

                           Tick ( ) if you know this.

                           ▶   A sequence of characters that are enclosed or surrounded by a single (‘ ’) or double (“ ”)
                             quotes is known as a string.

                           ▶  A list is a type of container that is used to store a list of values of any type.

                       92   Premium Edition-VIII

| 88 89 90 91 92 93 94 95 96 97 98 |