A list is a built-in Python data structure that stores an ordered collection of items, which can be of mixed types. Lists are mutable, meaning you can change their content after creation.
my_list = [1, 2, 3, 4, 5]
mixed_list = [1, "two", 3.0, True]
# 1. Accessing elements
fruits = ["apple", "banana", "cherry"]
print(fruits[0]) # Output: apple
# 2. Adding elements
fruits.append("orange")
print(fruits)
# Output: ['apple', 'banana', 'cherry', 'orange']
# 3. Removing elements
fruits.remove("banana")
print(fruits)
# Output: ['apple', 'cherry', 'orange']
# 4. Slicing lists
numbers = [10, 20, 30, 40, 50]
print(numbers[1:4])
# Output: [20, 30, 40]
# 5. List comprehension
squares = [x**2 for x in range(6)]
print(squares)
# Output: [0, 1, 4, 9, 16, 25]