Page 157 - Plus_V2.2_C8_Flipbook
P. 157

Program 13: To traverse the nested lists.












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








                      Slicing the List

                 List slicing refers to a part of a list. In Python, list slicing is done by using the Slicing operator(:).
                 The syntax of slicing the list is as follows:

                 name of the list[ start : stop : step ]
                 start is the start position of the list.

                 stop is the end position of the list.
                 step is the increment of the list (the step parameter is optional and by default is 1).

                  Program 14: To perform the slicing of lists.
















                      List Methods
                 To make the use of lists easier, Python provides various built-in methods. These methods are associated

                 with list objects and are called using the dot (.) notation. Let’s explore them.
                 If you could assemble a team of legendary heroes and mythical creatures using Python lists, who
                 would you include in your lineup? How would you modify the list to optimise your team's strengths and

                 weaknesses for epic battles and daring quests?
                 The following table describes the various built-in methods:











                                                                                      Functions and String in Python  155
   152   153   154   155   156   157   158   159   160   161   162