PyPyPath

Module 5: Lists in Python

Creating Lists

A list stores many values in one variable — like a shopping list or a column of numbers. Lists use square brackets [ ].

About 8 minutes

Creating a list

Example code
fruits = ["apple", "banana", "mango"]
numbers = [10, 20, 30]
mixed = ["Alice", 25, True]  # different types allowed
print(fruits)
print(numbers)
List = ordered items in [ ]

apple

index 0

banana

index 1

mango

index 2

Empty list

Example code
empty = []
also_empty = list()
print(len(empty))  # 0
Practice

Create a list of 3 hobbies and print it and its length.

Key takeaways

  • Lists use square brackets: [item1, item2, ...].
  • Items stay in order.
  • len(my_list) tells how many items.

Quick check: Creating Lists

Question 1 of 2

Which creates a list?