String Length with len()
Learn how to measure text length in Python with len(), including spaces, punctuation, and empty strings.
Sounds useful?
Jump into the interactive version.
No setup. No account. Just Python.
String Length with len()
Learn how to measure text length in Python with len(), including spaces, punctuation, and empty strings.
Jump into the interactive version.
No setup. No account. Just Python.
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:
len(text) to count characters in a string"" and space-only strings like " ">=.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.
Ready to practice this in the browser?
> Play now