Page 86 - tp_Modula_v2.0
P. 86

SLICING THE LIST

                  List slicing refers to a part of list. In python list slicing is done by using the Slicing operator(:).

                  Syntax: [beg:end]
                  here,
                      beg is the starting point

                      end is the stopping point which is not included
                  Program 8: Slicing operator illustration.

                      Program8.py
                   File  Edit  Format   Run   Options  Window    Help

                   list=[13, 25, 41, 63, 82]
                   print(list[0:4])
                   print(list[1:3])
                   print(list[:-3])
                   print(list[-1:])
                   print(list[:])



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

                      Output

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




                      CHANGING THE LIST ELEMENT

                  Lists is mutable which means the elements of a list can be changed or new elements can be
                  added into a list by using an assignment operator (=).
                  Program 9: Changing elements of a list.
                      Program9.py
                   File  Edit  Format   Run   Options  Window    Help
                   list=[13, 25, 41, 63, 82]
                   list[1]=50
                   list[3]=45
                   print(list[:])



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

                      Output

                   [13, 50, 41, 45, 82]






                   84     Touchpad MODULAR (Version 2.0)
   81   82   83   84   85   86   87   88   89   90   91