Skip to content

Python Create List

Syntax

Lists in Python are created by enclosing a sequence of items in square brackets [].

# Creating an empty list
empty_list = []
# Creating a list with elements
numbers = [1, 2, 3, 4, 5]
fruits = ["apple", "banana", "cherry"]

Example

# Creating and displaying a list of favorite colors
favorite_colors = ["blue", "green", "red", "yellow"]
print(f"My favorite colors are: {favorite_colors}")