lists in python | Python Lists

By | December 25, 2019
Spread the love

lists in Python contain any type but a list is also a Python type. and a list can also contain a list.
A list contains any Python type means you can store any type of data in it e.g strings booleans and floats etc.
Lists are used for storing values of different datatypes rather than creating a bunch of variables for it.

lists in Python

Examples of List:

If you want to store the height of your family members. Then you can store all the values.

Each will be separated with commas and assign to a single variable and surrounded by square brackets

it means that you can store values of multiple datatype variables in a single variable.

example:

familyHeights = ["kelly" , 1.1  , "merry" , 2.2 , "belly" , 3.2 , "lolly" , 4.5]

above is the example of a list

You can also create a list in the following manner and you can understand it easily. create a separate list and separate it by comma

familyHeights = [["kelly", 1.1],
           ["merry", 2.2],
                  ["belly", 3.2],
           ["lolly", 4.5] ]

Examples of Lists in Python


[1, 3, 4, 2]
           out put     [1, 3, 4, 2]

[[1, 2, 3], [4, 5, 7]]



[[1,2,3], [4,5,7]]

[1+2,"a"*5, 3]


       out put     [3, 'aaaaa', 3]
  •  
    78
    Shares
  • 76
  •  
  •  
  •  
  • 2
  •  
  •  
  •   
  •   
  •   
  •   
  •  

One thought on “lists in python | Python Lists

  1. Pingback: data types in Python | Python Data types | Free Courses Online Hub

Leave a Reply

Your email address will not be published. Required fields are marked *