Articles → Python → List In Python
List In Python
What Is The List?
Syntax
Variable_name = [item1, item2…..]
Example
classmates = ["Karan","sumit","amit”]
print(classmates)
Accessing The Individual Elements In The List
classmates = ["Karan","sumit","amit"]
print (classmates[0])
print (classmates[1])
print (classmates[2])
Changing The Value Of The List
classmates = ["Karan","sumit","amit"]
print(classmates)
classmates[1] = "Tarun"
print(classmates)
Creating A List Of Multiple Data Types
persondata = ["Karan" , 35, "India",12.5]
print(persondata)
Accessing Nested Lists In Python
nested_list = [1,2,[3,4]]
print("Element in nested list:", nested_list[2][0], " and ", nested_list[2][1])
Empty List
empty_list = []
print("Display empty list:", empty_list)