What is syntax?
Every programming language has its own rules - its syntax. It’s like grammar in human languages. You can’t just write words in any order and expect people to understand. The same goes for programming. Python’s syntax is known for being clean and readable. But it still has rules you must follow, or your code won’t run.The importance of syntax
Think about these two sentences:- “The cat sat on the mat” ✓ (correct English)
- “Cat the on mat sat the” ✗ (same words, wrong order)
Python’s unique feature: Indentation
Most languages use{} brackets. Python uses indentation (spaces):
Indentation rules
Python won’t run if your indentation is wrong. This is the #1 beginner mistake!
Python style guide (PEP8)
Beyond just syntax rules that make code run, Python has style guidelines that make code readable. These are called PEP8 (Python Enhancement Proposal 8) - the official style guide for Python code. PEP8 covers things like:- Using 4 spaces for indentation (not tabs)
- Limiting lines to 79 characters
- Naming conventions (like
user_nameinstead ofuserName) - Where to put spaces around operators
Following PEP8 isn’t required for code to run, but it makes your code look professional and easier for others to read.
That’s all for now
Syntax is just how you write Python code - the rules you follow. Right now, remember these basics: Python cares about spelling, order, and especially indentation. As we move through the course, you’ll naturally pick up the specific syntax rules for each concept.What’s next?
Now that you understand Python’s rules, let’s see what happens when we break them!Python errors
Understanding when code doesn’t run