Basic HTML Version

|  | Table of Contents |  | View Full Version

Page 91 - 2607_Traclpad_Pro_5.1_flipbook_C8
P. 91

    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

| 86 87 88 89 90 91 92 93 94 95 96 |