πŸ”’ Lists

✍ Datatypes so far…

  • Strings β€œcharacters in quotes”
  • Integers 42
  • Floats 4.2
  • Booleans True or False
  • Variables score = "bob" Each datatype is ONE piece of information.

✍ Lists

Datatype used to store a collection of different pieces of information, in order, under a single variable name.

numbers = [5, 6, 7, 8]
#  index   0  1  2  3

List Practice

numbers = [5, 6, 7, 8]
#  index   0  1  2  3

# What will print?
do_now = ["words", "stuff", "wrong", "this", "right", "question", "got", "you"]
print do_now[7] + do_now[6] + do_now[3] + do_now[2]

Putting Things Into a List

suitcase = []
print suitcase
suitcase.append("sunglasses")
print suitcase

What does .append() do?

  • What if we wanted to find the average of an entire class?
  • What if we wanted to add another subject?
  • What if we don’t want to type the same thing over and over and over and over and over and over and over and over and over again?