Cet article n’est pas encore traduit, il est donc affiché en anglais.
Python Code Not Running in VS Code? Fix SyntaxError, NameError and IndentationError
Write and run Hello World in VS Code, then fix the three errors every Python beginner meets: SyntaxError, NameError and IndentationError.
This is lesson 2 of my Python beginner course. You will write and run your first program, then break it on purpose three times so you can read Python's error messages without fear.
Lesson 1 is here: install Python 3.14 on Mac and set up VS Code.
▶ WATCH ON YOUTUBEWatch the video
▶ WATCH ON YOUTUBEFull video
Write Hello World
- Create a folder named
python-beginner-courseand open it in Visual Studio Code. - Choose New File and name it
hello_world.py. The Python extension sees the.pyending and treats it as Python. - Type exactly:
print("Hello, World!")print() shows information in the terminal.
Run it
Save the file and open the integrated terminal. On macOS:
python3 hello_world.pyThe terminal prints Hello, World!. Your first program works.
Error 1: SyntaxError (quotes that do not match)
A Python string can use double quotes or single quotes, but the opening and closing quote must be the same.
print("Hello, Python!')Run it and Python reports:
SyntaxError: unterminated string literalPython could not find the matching quote. Fix: use the same quote on both sides.
print('Hello, Python!')Error 2: NameError (wrong capital letter)
Python is case-sensitive. Print and print are different names.
Print("Hello, World!")Python raises a NameError because Print is not defined. The message even suggests the right name, lowercase print. Fix: change the capital P to lowercase.
Error 3: IndentationError (missing spaces)
Code inside an if block must be indented. This works:
if True:
print("Hello, World!")Remove the four spaces and run it again:
if True:
print("Hello, World!")Python raises an IndentationError and says it expected an indented block after if. Fix: put the four spaces back.
Quick table
| Error | Usual cause | Fix |
|---|---|---|
SyntaxError: unterminated string literal |
Opening and closing quotes differ | Use matching quotes |
NameError |
Wrong capital letter or a typo in a name | Check spelling and case |
IndentationError |
Code in a block is not indented | Indent with four spaces |
Read the last line of the error first. It names the error type and usually tells you what Python expected.
Links
- Full video: https://youtu.be/zgGw7yvVlAg
- Lesson 1: install Python 3.14 and VS Code
- A first real project: build a chatbot in Python from scratch
Which error did you hit first?


