A Brief Introduction to Lists

We know how to use variables to store values. So far our examples have been pretty small and well contained. What if we need to store 1,000 sets of data... are we really going to make 1,000 variables? In Python we use lists to store an ordered sequence of items.

my_first_list = [3, 5, 6]
# A list of items are enclosed by square brackets
# Each item in a list is called an element
# Every element is separated by commas
# And that's right, a variable can store a list just like it can for
# strings, numbers or booleans
another_list = [99, 100, 34, 22, 343]

# List can be of other types
list_of_strings = ['hey', 'there']
list_floats = [3.0, 2.2]
list_of_mixed_values = [12, 23.0, 'still works']

There are a lot more to lists which we will cover at a later section. For now, being able to create them and store in variables is enough to dive into Pygame!

Last updated