3.06
Completed
String Length with len() String Length with len()

Learn how to measure text length in Python with len(), including spaces, punctuation, and empty strings.

String Length with len()

Sounds useful?

Jump into the interactive version.

No setup. No account. Just Python.

Interactive Python lesson

String Length with len()

This Block teaches one very useful Python skill: measuring how long a string is. You will use the built-in len() function to count characters in text, store the result in variables, and use that number in simple messages and checks.

Along the way, you will see that string length is not only about letters. Spaces count. Punctuation counts. Digits inside text count. Even the difference between an empty string and a string containing one space matters more than beginners usually expect.

What you will learn:

  • Use len(text) to count characters in a string
  • Store string lengths in variables
  • Understand that spaces, punctuation, and digits count as characters
  • Handle empty strings like "" and space-only strings like " "
  • Use string length inside simple f-string messages
  • Compare string length with a minimum value using >=
  • Measure cleaned text after using .strip()

By the end, you will be able to answer questions like “How many characters did the user type?” and “Is this username long enough?” without overthinking it. Tiny function, very useful habit.

> Start now 69 cards · about 8 min

Ready to practice this in the browser?

> Play now