List is the most versatile python data structure. Holds an ordered sequence of items.
Created by enclosing elements within [square] brackets. Each item is separated by a comma.
a = 2
list_a = [5, "Six", a, 8.2]
print(list_a)
# Output - [5, 'Six', 2, 8]
To access elements of a list, we use Indexing.
mobiles = ["1+", "Iphone", "POCO"]
print(mobiles[0]) # 1+
print(mobiles[1]) # Iphone
print(mobiles[2]) # POCO
.append(item) → Adds a single item to the end.
.remove(value) → Removes the first occurrence of a value.
mobiles = ["1+", "Iphone", "POCO"]
mobiles.append("Samsung")
print(mobiles)
mobiles.remove("1+")
print(mobiles)
# output
# ['1+', 'Iphone', 'POCO', 'Samsung']
# ['Iphone', 'POCO', 'Samsung']