Junior Codes
The Treasure Archive

Python Indexing and Slicing for Kids

Pick one item, or a whole section, by its position.

Start Wonderwild free with Pip

Try 5 starter activities free. Full access is ₹499 a year.

This mission is part of full access. The first missions are free to try.

Indexing & slicing, explained simply

Every item in a list has a position number called an index. Python starts counting at 0, so the first item is at index 0, the second at 1, and so on. You ask for an item with square brackets: shelf[0].

Negative indexes count from the end: shelf[-1] is the last item. This saves you from working out how long the list is.

A slice takes a section: shelf[1:3] gives the items at positions 1 and 2, stopping before 3. Strings can be indexed and sliced exactly the same way, one letter at a time.

Example: Take books from the shelf

shelf = ["atlas", "comic", "diary", "poems"]
print(shelf[0])
print(shelf[-1])
print(shelf[1:3])
print("treasure"[0:5])

Output

atlas
poems
['comic', 'diary']
treas

Try this

  • Print the second letter of your name using an index.
  • Ask for shelf[10] and read the error. What does it tell you?
  • Use shelf[::-1] and work out what the extra part of the slice does.

Practise it in Wonderwild

“The secret shelf”

Mission 20 in The Treasure Archive, one of 36 Python missions in Wonderwild.

Your child writes and runs real Python in the browser while Pip reacts to every line. Nothing to install. For ages 7+.

Start Wonderwild free with Pip

Try 5 starter activities free. Full access is ₹499 a year.

This mission is part of full access. The first missions are free to try.

Questions parents and kids ask

Why does Python count from 0?+

The index measures how far an item is from the start. The first item is zero steps away. Most programming languages work this way.

What is an IndexError?+

It means you asked for a position that does not exist, such as index 4 in a list of four items (the last one is at index 3).

Prefer learning with a teacher?

Our live Python for Young Developers course teaches these ideas in small online classes led by a software engineer, with projects and feedback. Every live course also includes 12 months of full Wonderwild access for practice.

See the Python for Young Developers course