← Python

len() function

len() returns the number of characters in a string (or items in a sequence)

What it does: 'Python' has 6 characters, so len() returns 6. The empty string has zero characters, so len('') returns 0. Count each character: H-e-l-l-o = 5. H-i = 2 characters. Count including the space: H-e-l-l-o-space-W-o-r-l-d = 11. A space is a character — len() counts everything between the quotes. A-l-i-c-e = 5 characters. len() returns a whole number — the count of characters.

Common mistakes: Line 2 is missing parentheses. Should be: length = len(name). Line 2 puts the variable in quotes. Should be: len(word).

Class: _____________________  ·  Name: _____________________  ·  Date: _________

Free printable worksheet with full answer key — or add this module to a journey and assign it to your class.

Take this worksheet further — free with Cloodit

Each concept is reinforced from every angle — learned, then applied, then tested.

Learning
Duo
What is len("Hello")?
56
Matches
❌ len(Hello)
Error: Missing quotes
Applying
Meanings
Term
len("Hello")
Meaning
len() counts characters - len("Hello") gives 5.
Practice
length = len("Number of letters in this sentence.")
Testing
Gaps
length = ("Hello")
Check Answer
Spots
1name = "Alice"
2length = len name

Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.

The 'Parrotfish' badge — Function Builder, one of Cloodit's 106 collectible badges
Students earn collectable badges

Over 100 of them, across seven natural biomes.

Study Buddy
Students build a real study resource

Turns their work into revision material ready for Flash Cards and Exam study.

Diamond Dash — one of Cloodit's live, competitive Sprint games
Students lock in with Sprints

Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.

A Cloodit certificate of achievement, ready to personalise and print
Custom printable certificates

Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.

Quick Questions

1. What is len("Hello")?
A. 5 ✓
B. 6
Count each character: H-e-l-l-o = 5
2. What is len("Hi")?
A. 3
B. 2 ✓
H-i = 2 characters
3. What is len("Hello World")?
A. 11 ✓
B. 10
Count including the space: H-e-l-l-o-space-W-o-r-l-d = 11
4. Do spaces count in len()?
A. No
B. Yes ✓
A space is a character — len() counts everything between the quotes
5. After name = "Alice", what is len(name)?
A. 5 ✓
B. 4
A-l-i-c-e = 5 characters

Match the Pairs

len(Hello) Error: Missing quotes
len('cat', 'dog') Error: Too many arguments
n = len('Python') Valid: n stores 6
len('') Ok: Returns 0
print(len('Hello')) Output: 5
w = 'cat' print(len(w)) Output: 3

Key Term

len("Hello")
len() counts characters - len("Hello") gives 5.~~len("Hello World")

Fill in the Blanks

1. length = len("Hello")
2. name = "Alice" result = len(name) print(result)
3. message = "Hi there" size = len(message)
4. word = "Python" length = len(word) print(length)
5. text = "Hello World" count = len(text) print(count)

Spot the Error

Question 1
A name = "Alice"
B length = len name
C print(length)
Line B — Line 2 is missing parentheses. Should be: length = len(name)
Question 2
A word = "Python"
B size = len("word")
C print(size)
Line B — Line 2 puts the variable in quotes. Should be: len(word)
Question 3
A message = "Hello"
B count = length(message)
C print(count)
Line B — Line 2 uses the wrong function name. Should be: len(message)
Question 4
A text = "Hi there"
B size = len(text)
C print(size)
D new_len = len(Hello)
E print(new_len)
Line D — Line 4 is missing quotes around Hello. Should be: len("Hello")
Question 5
A name = "Bob"
B name_length = len(name)
C message = "Python Code"
D msg_len = len message
E print(msg_len)
Line D — Line 4 is missing parentheses. Should be: msg_len = len(message)
For Teachers

Create a free class, add this module to a journey, and track who's stuck.

Create a free teacher account →

No credit card. No setup fee. Make a class and invite students in under three minutes.

For Students

Practice this topic interactively, track progress, and unlock badges.

Start Learning Free →

Have a class code?