Create a List
Create a list called 'colors' with 3 colors: "red", "green", "blue". Print the list.
Lists store multiple values in one variable.
Create a list:
fruits = ["apple", "banana", "orange"]
numbers = [1, 2, 3, 4, 5]
Access items by index (starting from 0):
print(fruits[0]) # apple
print(fruits[1]) # banana
Get list length:
print(len(fruits)) # 3
Add items:
fruits.append("grape")
Loop through list:
for fruit in fruits:
print(fruit)
Create a list called 'colors' with 3 colors: "red", "green", "blue". Print the list.
Given list: numbers = [10, 20, 30, 40, 50] Print the first element (10). Print the last element (50).
Create a list: items = ["a", "b", "c", "d"] Print how many items are in the list.
Given: fruits = ["apple", "banana", "cherry"] Print each fruit on a new line using a for loop.
Start with: animals = ["cat", "dog"] Add "bird" to the list. Print the updated list.