Page 92 - TP_V5.1_C8_fb
P. 92

Program 11: To create a list.

                      Program11.py
                   File  Edit  Format   Run    Options   Window    Help

                   a= [10, 20, 30, 40, 50]                                      Output
                   print (a[2])                                               30



                  Let us study some of the ways through which we can create different types of lists.

                  Empty List

                  An empty list in Python is created using [ ].

                  Program 12: To create an empty list.

                      Program12.py
                   File  Edit  Format   Run    Options   Window    Help

                   picnic=[]
                   print (picnic)                                               Output
                   exam= list()                                               []
                   print (exam)
                                                                              []




                  Mixed Data Type List
                  Mixed data type list can be created by placing values of different data types such as integer,
                  string, double, etc.

                  Program 13: To create a mixed data type list.

                      Program13.py
                   File  Edit  Format   Run    Options   Window    Help

                   a=['Ravi', 'Bhatt', 12, 13, 14]                              Output
                   print (a)                                                  ['Ravi', 'Bhatt', 12, 13, 14]




                  Nested List
                  A list can have a list in itself as an element.
                  Program 14: To create a nested list.


                      Program14.py
                   File  Edit  Format   Run    Options   Window    Help
                                                                                Output
                   a=['Lakshaya', 'Sameer', 10, 20, [1,2,3],7]
                                                                              ['Lakshaya', 'Sameer', 10, 20,
                   print (a)
                                                                              [1, 2, 3], 7]




                   90   Premium Edition-VIII
   87   88   89   90   91   92   93   94   95   96   97