Articles → Python → List in python

List in python

What is list?


Variable_name = [item1, item2…..]


classmates = ["Karan","sumit","amit”]

Picture showing the output of the list in th python

Click to Enlarge

Accessing the individual elements in list

classmates = ["Karan","sumit","amit"]
print (classmates[0])
print (classmates[1])
print (classmates[2])

Picture showing accesing the elements of the list individually

Click to Enlarge

Changing the value of list

classmates = ["Karan","sumit","amit"]


classmates[1] = "Tarun"


Picture showing how to change the value of the list in python

Click to Enlarge

Creating a list of multiple data types

persondata = ["Karan" , 35, "India",12.5]


Picture showing how to create a list of multiple data types

Click to Enlarge

Accessing nested list in python


nested_list = [1,2,[3,4]]
print("Element in nested list:", nested_list[2][0], " and ", nested_list[2][1])

Picture showing how the nested list is accessed in python

Click to Enlarge

Empty list

empty_list = []

print("Display empty list:", empty_list)

Picture showing the empty list in python

Click to Enlarge

Posted By  -  Karan Gupta
Posted On  -  Wednesday, February 13, 2019
Updated On  -  Thursday, May 2, 2019


Your Email Id  
Query/FeedbackCharacters remaining 250