© Sloan Kelly  2019
Sloan KellyPython, PyGame, and Raspberry Pi Game Developmenthttps://doi.org/10.1007/978-1-4842-4533-0_7

7. Containers

Sloan Kelly1 
(1)
Niagara Falls, ON, Canada
 
Up until now, we’ve mostly stored a single value in a variable like this:
playerName = 'Sloan'
Python allows you to store multiple values in the same variable. In this, you are assigning a container object a name. There are three different types of containers:
  • Tuple

  • List

  • Dictionary

There are cases when you will use one over the other, and we’ll discuss the pros and cons of each use.

Container Nomenclature

Container subparts are called elements. Each element can be indexed using the ‘[‘and’]’ characters and specifying a number between 0 and n-1 where ‘n’ is the number of items ...

Get Python, PyGame, and Raspberry Pi Game Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.