Table of Contents
Every language has rules. English has grammar. Maths has order of operations. And Python has syntax.
Syntax is simply the set of rules that define how you write code that Python can actually understand. Break the rules, and Python throws an error. Follow them, and everything runs smoothly.
The good news?
Python’s syntax is one of the cleanest and most readable among all programming languages. It almost reads like English. Almost. Let’s go through the rules that matter most.
Rule 1 — Indentation
This is the big one. If there’s one syntax rule Python takes seriously, it’s indentation.
In most programming languages, indentation is just a style choice — you do it to make your code look neat. In Python, it’s mandatory. Python uses indentation to understand the structure of your code — which lines belong together, which block of code runs under which condition.
Take this example:
if 5 > 2:
print("Five is greater than two!")
That gap before print() — those 4 spaces — tell Python that this line belongs inside the if block. Remove those spaces and Python will throw an error, because it genuinely doesn’t understand what you meant.
The standard is 4 spaces per indentation level. You can use tabs too, but don’t mix tabs and spaces — Python will get confused, and honestly, so will you.
What does ‘mixing’ look like? Something like this — one line indented with a tab, the next with spaces. They look identical to your eyes but Python sees them as completely different characters. So pick one — ideally 4 spaces — and stick to it throughout.
Rule 2 — Whitespace
Related to indentation but a slightly different idea. Whitespace refers to all the blank space in your code — spaces between words, blank lines between sections, gaps between operators.
Python is sensitive to whitespace within your indentation. But outside of that, you have freedom. Adding blank lines between sections of code is actually encouraged — it makes your code easier to read.
For example, this is perfectly valid:
print("Hello")
print("World")
The blank line between them does nothing to the execution — Python just skips it. But to a human reading the code, it signals a natural pause. Use blank lines generously. Your future self (rereading old code) will thank you.
Rule 3 — Case Sensitivity
Python is case sensitive. That means name, Name, and NAME are three completely different things to Python.
Try this in your head — if you create a variable called name and then try to print Name, Python will say it doesn’t exist. Because as far as Python is concerned, it doesn’t.
name = "Aryan"
print(name) # works
print(Name) # error — Name is not defined
This catches a lot of beginners off guard. If your code is throwing a ‘not defined’ error and you’re sure you defined it — check your capitalisation. Nine times out of ten, that’s the culprit.
Rule 4 — Keywords & Reserved Words
Python has a set of words it has already claimed for itself. These are called keywords or reserved words — and you cannot use them as variable names or function names.
Some common ones you’ll run into soon:
if, else, elif, for, while, def, return, import, True, False, None, and, or, not, in, is
For example, you can’t do this:
if = 10 # Error — "if" is a keyword, Python won't allow it
VS Code actually helps you here — keywords show up in a different colour (usually purple or blue depending on your theme). So if you name a variable and it changes colour unexpectedly, that’s Python’s way of saying — hey, that word is taken.
Quick Recap
- Indentation is mandatory in Python — use 4 spaces consistently
- Don’t mix tabs and spaces — pick one and stick to it
- Blank lines are ignored by Python but help humans read code
- Python is case sensitive — name and Name are different
- Keywords are reserved — you can’t use them as variable names
These are the ground rules. They might feel like restrictions right now, but once they become second nature — and they will — you’ll actually appreciate how clean and readable Python code looks because of them. Next up, we talk about Variables and Data Types. See you there
