Introduction to Python
  • Introduction
  • Preface
  • Background
  • Installing Python
  • Getting Started
  • Basics
    • More Printing
    • Strings
    • Numbers
    • Exercises
    • Comments
  • Variables
    • Operators
    • Type Conversion
    • Exercises
    • A Brief Introduction to Lists
    • Game Exercise
  • Human Input
  • Functions
    • First Functions
    • Why Functions
    • Exercises
  • Indentation
  • Decisions
    • Booleans
    • Logical Operators
    • If Statements
    • Elif and Else Statements
    • Exercises
    • Rock, Paper, Scissors
    • Game Exercise
    • Game Exercise 2
  • Lists
  • Loops
    • For Loops
    • While Loops
  • More Data Structures
    • Tuples
    • Dictionaries
  • Pygame
  • Extra Content
    • Computers and Code
    • More About Python
    • For Loops with Range
    • List Slicing
Powered by GitBook
On this page
  1. Variables

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!

PreviousExercisesNextGame Exercise

Last updated 6 years ago