You've installed Python. You've set up VS Code. You're ready to write code.
And then... you get an error message.
That wall of red text. The intimidating terminology. The creeping doubt that maybe programming isn't for you.
I'm going to tell you something that will change your entire relationship with coding:
Error messages are not your enemy. They're your most helpful friend.
The Mindset Shift
Every error message is Python saying:
"Hey, I couldn't do what you asked. But here's exactly what went wrong and exactly where it happened."
That's incredibly helpful. The problem is that beginners don't know how to read them.
Let's fix that.
Anatomy of an Error Message
Here's a simple error:
>>> print("Hello
File "<stdin>", line 1
print("Hello
^
SyntaxError: unterminated string literal (detected at line 1)
Every piece of this is trying to help you:
| Part | What it tells you |
|---|---|
File "<stdin>", line 1 |
Where the error happened |
print("Hello |
The problematic code |
^ |
Exactly where Python got confused |
SyntaxError |
The category of error |
unterminated string literal |
Plain English explanation |
The string was never closed. Python told you exactly what's wrong.
The Four Errors You'll See Constantly
As a beginner, 90% of your errors will be one of these four:
1. SyntaxError — Grammar Problems
You violated Python's grammar rules:
print("Hello" # Missing closing parenthesis
if True # Missing colon
print('Hello") # Mismatched quotes
Fix strategy: Look at where the ^ points. The error is usually at or just before that position.
2. NameError — Unknown Names
You're using a name Python doesn't recognize:
print(message) # Variable was never defined
Print("Hello") # Capital P (Python is case-sensitive!)
pirnt("Hello") # Typo
Fix strategy: Check spelling carefully. Print and print are completely different to Python.
3. IndentationError — Whitespace Problems
Your indentation is inconsistent:
if True:
print("Hello") # Needs to be indented!
Fix strategy: Use 4 spaces for indentation. Never mix tabs and spaces. Configure your editor to handle this automatically.
4. TypeError — Incompatible Types
You're trying to do something with incompatible data types:
"Hello" + 5 # Can't add a string and an integer
Fix strategy: Convert data to compatible types:
"Hello" + str(5) # "Hello5"
# Or use f-strings
f"Hello{5}" # "Hello5"
The Simplest Debugging Technique
When your code isn't working and you don't know why, add print() statements:
def calculate_total(prices):
total = 0
for price in prices:
print(f"Adding {price}, total is now {total}") # Debug
total + price # BUG: missing = sign!
return total
When you run this, you'll see that total never changes. The bug becomes obvious: total + price calculates a value but never assigns it back. The fix is total += price.
This technique is called "print debugging." It's not fancy. It works for 80% of problems.
The Debugging Mindset
What separates frustrated beginners from effective programmers:
- Stay calm. Frustration clouds thinking. If you're angry, take a break.
- Read the ENTIRE error message. Every word matters.
- Check your assumptions. Print variables to verify they contain what you think.
- Question everything. Even code you're "sure" is correct might be wrong.
- Isolate the problem. Remove code until the bug disappears. Add code back until it returns.
The Truth About Professional Developers
Here's something that might surprise you:
Professional developers encounter errors constantly. Multiple times per hour. Every single day.
The difference is they:
- Read error messages without panic
- Understand what the error is telling them
- Fix it and move on
They don't write perfect code. They write code, see errors, fix them, and repeat. This is the job.
The moment you internalize this, you'll stop feeling like errors mean you're failing—and start seeing them as a normal, expected part of programming.
Try This Now
Open your terminal and type python3 to enter the REPL. Then intentionally create errors:
>>> print("Hello
# See what SyntaxError looks like
>>> print(undefined_variable)
# See what NameError looks like
>>> "hello" + 5
# See what TypeError looks like
Get comfortable with these messages in a safe environment. When they appear in real code, you'll recognize them immediately.
I'm writing a book called "Zero to AI Engineer: Python Foundations" that takes you from complete beginner to building AI-powered applications. This is from Chapter 5. If you want more content like this, follow me here or subscribe to my Substack for chapter previews. https://substack.com/@samuelochaba?utm_campaign=profile&utm_medium=profile-page
Top comments (0)