Find Mistake: String + Int Concatenation
Find the Mistake Easy
Question
This code raises a TypeError. What is wrong?
Code
age = 25
msg = "I am " + age + " years old"
Hint
You can't add a string and an integer directly.
Explanation
You cannot concatenate a string and an integer with +. The fix is to convert age to a string: msg = 'I am ' + str(age) + ' years old' or use an f-string: msg = f'I am {age} years old'.
Related Resources
Related Lessons
- Strings
String concatenation.
Look up unfamiliar terms
A beginner-friendly glossary explains jargon in plain English — variables, functions, DOM, Promise, and more.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.
Build real projects
Apply what you learned by building guided projects with starter code and solutions.