The Adventures of Ava the Astronaut: Learning Python One Planet at a Time.
Part 6 Conceptual Complete

Part 6: The Treasure Chest — Lists, Tuples, and Strings

The Adventures of Ava the Astronaut: Learning Python One Planet at a Time

Updated July 17, 2025 6 min read

Part 6: The Treasure Chest — Lists, Tuples, and Strings

The Adventures of Ava the Astronaut: Learning Python One Planet at a Time


The Ship’s Cargo Hold

Ava’s journey has been a huge success. She has collected strange alien plants from Veridia, shimmering crystals from the Looping Nebula, and geological samples from a dozen asteroids. Her ship’s cargo hold is getting full, and she needs a way to keep track of everything.

Using a single variable for each item would be a disaster. What if she has 500 items? She would need 500 separate variables! There has to be a better way.

“Py,” she called out, “I need a way to store a whole collection of items together, like an inventory list that I can add to and remove from.”

“Of course, Commander,” Py replied. “You need a data structure called a List. A list is an ordered, changeable collection of items. It is the perfect tool for managing your inventory.”


Your First Inventory: Creating a List

A list in Python is created by placing items inside square brackets [], separated by commas. A list can hold items of any data type — strings, integers, floats, booleans, or even other lists!

# An empty list
empty_inventory = []
# A list with some starting items
inventory = ["shimmering crystal", "alien plant", "space helmet", "navigation chart"]
print(inventory)

Output: ['shimmering crystal', 'alien plant', 'space helmet', 'navigation chart']


Managing the Cargo: List Operations

Now that we have a list, what can we do with it? Lists are incredibly versatile. Let’s explore the most important operations.

Accessing Items by Index

Each item in a list has an index, which is its position number. Indexing starts at 0, not 1. So the first item is at index 0, the second at index 1, and so on.

inventory = ["shimmering crystal", "alien plant", "space helmet", "navigation chart"]
first_item = inventory[0]
print(f"My first collected item was: {first_item}")
last_item = inventory[-1] # Negative index! -1 means the last item.
print(f"The most recent item is: {last_item}")

Adding and Removing Items

Here are the most common ways to modify a list:

MethodWhat It DoesExample
append(item)Adds an item to the end of the list.inventory.append("laser")
insert(index, item)Inserts an item at a specific position.inventory.insert(0, "shield")
remove(item)Removes the first occurrence of a specific item.inventory.remove("alien plant")
pop(index)Removes and returns the item at a specific index.inventory.pop(2)
inventory = ["shimmering crystal", "alien plant", "space helmet"]
# Ava finds a new item
inventory.append("mysterious alien cube")
print(f"Found a cube! Inventory: {inventory}")
# Ava uses her space helmet
inventory.remove("space helmet")
print(f"Used the helmet. Inventory: {inventory}")

Slicing: Grabbing a Sub-Section

You can grab a portion of a list using slicing. The syntax is list[start:end], where start is inclusive and end is exclusive.

crew = ["Ava", "Py", "Zara", "Leo", "Nova"]
# Get the first three crew members (index 0, 1, 2)
first_three = crew[0:3]
print(f"First three: {first_three}")
# Get everyone from index 2 to the end
from_zara = crew[2:]
print(f"From Zara onwards: {from_zara}")

Other Useful List Tricks

numbers = [3, 1, 4, 1, 5, 9, 2, 6]
print(f"Length of list: {len(numbers)}") # How many items?
print(f"Sorted: {sorted(numbers)}") # Returns a new sorted list
print(f"Is 5 in the list? {5 in numbers}") # Check if an item exists

The Unchangeable Coordinates: Tuples

Ava gets a critical mission: travel to the fixed coordinates of a hidden starbase. These coordinates must never be changed by accident. For this, Python has a data structure called a tuple.

A tuple is just like a list, but it is immutable — meaning it cannot be changed after it is created. You create a tuple using parentheses () instead of square brackets.

# The coordinates for the secret starbase
starbase_coords = (12.345, -87.654, 23.0)
print(f"Starbase is located at: {starbase_coords}")
print(f"X coordinate: {starbase_coords[0]}") # You can still ACCESS items
# But what happens if we try to CHANGE it?
# starbase_coords[0] = 99.9 # Uncomment this line and you'll get a TypeError!

You use tuples for data that should remain constant throughout your program, like coordinates, RGB color values (255, 0, 0), or important configuration settings. If you accidentally try to change a tuple, Python will raise an error, protecting your data.


Mastering Strings

Strings are actually very similar to lists in some ways — they are ordered sequences of characters, and you can access individual characters by index and use slicing. But strings also come with their own powerful set of methods.

message = " Hello, Commander Ava! "
print(message.upper()) # " HELLO, COMMANDER AVA! "
print(message.lower()) # " hello, commander ava! "
print(message.strip()) # "Hello, Commander Ava!" (removes extra spaces)
print(message.replace("Ava", "Zara")) # " Hello, Commander Zara! "
# Splitting a string into a list of words
words = "one small step for man".split(" ")
print(words) # ['one', 'small', 'step', 'for', 'man']
# Joining a list of words back into a string
joined = " - ".join(words)
print(joined) # "one - small - step - for - man"
MethodWhat It DoesExample Result
.upper()Converts to uppercase"HELLO"
.lower()Converts to lowercase"hello"
.strip()Removes leading/trailing whitespace"Hello"
.replace(old, new)Replaces occurrences of a substring"Hi World"
.split(separator)Splits string into a list["a", "b", "c"]
.join(list)Joins list elements into a string"a-b-c"

Mini-Project: “Space Inventory Manager”

Your mission is to create a program to help Ava manage her growing collection of space treasures.

Your Task:

  1. Create a list named inventory with at least four starting items (e.g., “laser pistol”, “star map”, “healing potion”, “oxygen tank”).
  2. Print the entire inventory with a header like “Current Inventory:”.
  3. Use append() to add a new item (e.g., “alien artifact”). Print the updated list.
  4. Use remove() to take an item out (e.g., “healing potion”). Print the updated list.
  5. Use an index to access and print the third item in your final inventory. (Remember: the third item is at index 2!)
  6. Print the total number of items using len().

Bonus Challenge: Use a for loop to print each item in the inventory on its own line, with a number next to it, like this:

1. laser pistol
2. star map
3. oxygen tank
4. alien artifact

Mission Complete!

You are now a master of the cargo hold! You can manage collections of items using lists, perform all sorts of operations on them, protect important data with tuples, and manipulate text with string methods. Your ability to handle large amounts of data is a huge leap forward in your programming journey.

Next, we will build an “Alien Encyclopedia” and learn how to store information in key-value pairs using Dictionaries! See you in Part 7!


This is Part 6 of a 10-part series: “The Adventures of Ava the Astronaut: Learning Python One Planet at a Time.”