In this lesson, you'll learn about Python's list data structure — one of the most powerful tools in your programming toolbox.
A list is a collection of items. You can store numbers, strings, or even other lists in a list. Lists are created using square brackets []
.
fruits = ["apple", "banana", "cherry"]
print(fruits[0]) # apple
print(fruits[1]) # banana
numbers = [1, 2, 3]
numbers.append(4) # [1, 2, 3, 4]
numbers.remove(2) # [1, 3, 4]
print(numbers[1]) # 3
print(numbers[-1]) # 4
print(numbers[:2]) # [1, 3]
for fruit in fruits:
print("I like", fruit)
Create a Python program that asks the user to enter 3 of their favorite foods. Store them in a list and print a menu using that list.
← Back to Dashboard