๐Ÿ PyQuest๐Ÿงบ Lists & Collections ยท โž• Growing Your List
โญ 0 XP๐Ÿ Python is waking upโ€ฆ

Growing Your List โž•

Lists aren't frozen โ€” you can add to them while your program runs!

.append() sticks a new item onto the end of a list:

squad = ["Ana"]
squad.append("Bo")
squad.append("Cy")
print(squad)        # โžœ ['Ana', 'Bo', 'Cy']
print(len(squad))   # โžœ 3

Read it out loud as "squad, append Bo" โ€” the list name, then a dot, then the thing you want to do to it.

You can even start with a totally empty list and fill it up:

collected = []
collected.append("first treasure!")

Your mission

You're packing for an adventure.

  1. Make a list called inventory with 2 starting items
  2. Use .append() three times to add 3 more items
  3. Print the finished inventory
  4. Print how many items you're carrying with len()

Your code

Press โ–ถ Run to see what your code does!