10 Common Python Mistakes Beginners Make (and How to Fix Them)
Every programmer makes these mistakes. The difference between a beginner and an experienced coder is just how fast they recognise them. Here are the ten we see most.
1. Missing quotes around text
print(Hello) # NameError: name 'Hello' is not defined
print("Hello") # fixed
2. Mismatched quotes
print("Hello') # SyntaxError
print("Hello") # fixed
3. = instead of ==
if hp = 0: # SyntaxError
if hp == 0: # fixed
4. Forgetting the colon
if hp > 0 # SyntaxError: expected ':'
if hp > 0: # fixed
5. Indentation problems
Lines inside an if, loop or function need 4 spaces. See our full guide to fixing IndentationError.
6. Adding text and numbers
hp = 30
print("HP: " + hp) # TypeError
print("HP: " + str(hp)) # fixed
print("HP:", hp) # also fine
7. input() always gives text
age = input("Age? ")
print(age + 1) # TypeError
print(int(age) + 1) # fixed
8. Misspelled names
Print is not print, and enemyhp is not enemy_hp. Python is case-sensitive, so check spelling when you see NameError.
9. Off-by-one with lists
Lists start at index 0. In a list of 3 items, team[3] raises IndexError. More in our lists guide.
10. A while loop that never ends
If nothing inside the loop changes the condition, it runs forever. Make sure something moves toward the stopping point (see for vs while).
The real tip: read the last line
Python error messages look long, but the last line names the problem and the line number shows where to look. Reading errors calmly is the most useful skill a beginner can build.
In Code Monsters Academy, a coach explains each of these errors in plain language right when they happen.