Page 131 - TP_Play_V2.2_Class8
P. 131

Program1: To print the different types of lists

                     Program1.py
                  File  Edit  Format   Run   Options   Window     Help

                  new_list1=[5, 6, 7, 8]                     #Homogeneous data elements
                  print(new_list1)


                  #changing the elements of list
                  new_list1=[5, "Orange", 15.5]              #Heterogeneous data elements
                  print(new_list1)



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

                  [5, 6, 7, 8]
                  [5, 'Orange', 15.5]



                 Nested List

                 A list that contains another list is called a nested list. The example of the nested list is given as follows:

                 To create nested list: L1 = [’Orange’, 2.0, 5, [10,20]]
                 Program 2: To print the nested list


                     Program2.py
                  File  Edit  Format  Run   Options  Window    Help

                  L1 = ['Orange', 2.0, 5, [10,20]]
                                                                                  Output
                  print(L1)                                                    ['Orange', 2.0, 5, [10, 20]]






                          Double Tap                                                 Century   #Information Literacy
                                                                                        21 st
                                                                                       Skills

                        1.  Write the syntax to create a list.


                        2.  Write an example of nested list.





                      MODIFYING THE LIST ELEMENTS


                 Lists are mutable, it means you can change the elements after the list is created. You can do this by
                 using an assignment operator (=).


                                                                                                     #List in Python 129
   126   127   128   129   130   131   132   133   134   135   136