7.02
Completed
List Length with len() List Length with len()

Learn how to count list items with len(), handle empty lists, and avoid confusing length with indexes.

List Length with len()

Sounds useful?

Jump into the interactive version.

No setup. No account. Just Python.

Interactive Python lesson

List Length with len()

Lists can hold multiple values, but sooner or later you need to know how many values are actually inside. This Block teaches you how to use len() with lists, store the result in a variable, print friendly count messages, and use the length in simple decisions.

You will also learn one very important beginner trap: list length is not the same thing as the last valid index. A list with 3 items has length 3, but its last valid index is 2. Tiny detail, big difference.

What you will learn:

  • Use len(my_list) to count how many items are in a list
  • Understand that empty lists have length 0
  • Store list length in a variable and reuse it in messages
  • Use list length with if and else
  • Tell the difference between string length and list length
  • Understand why the last valid index is len(my_list) - 1 for non-empty lists

By the end, you will be able to measure lists clearly and safely, without manually counting items like a tired spreadsheet worker.

> Start now 67 cards · about 6 min

Ready to practice this in the browser?

> Play now