Page 136 - Code_GPT_Class_8
P. 136

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

                   Output

                Orange Education
                65.5





                        Interdisciplinary Learning                                                    Lab Activity


                  Create a list of ten most common English idioms and phrases in Python.






                                 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?


              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 7: To perform the slicing of lists

                   Program7.py

                File  Edit  Format  Run   Options  Window    Help
                list1=[13, 25, 41, 63, 82]
                                                                                Output

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



              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.



                        CodeGPT (Ver. 4.0)-VIII
                134
   131   132   133   134   135   136   137   138   139   140   141