Python's syntax is unusually minimal, and almost all of that comes from one decision: using indentation instead of braces.
In PHP or JavaScript, { } marks where a block of code starts and ends. Python uses indentation — consistent spacing at the start of a line — for the exact same purpose:
if 5 > 2:
print("Five is greater than two!")
print("This line is part of the if too.")
print("This line is not — it lines up with if, not the code inside it.")Indentation is enforced, not optional
Mixing tabs and spaces, or using inconsistent indentation width, causes an IndentationError — this isn't a style suggestion, it's enforced by the language. The standard convention is 4 spaces per indentation level; most editors can be configured to insert 4 spaces automatically when you press Tab.
A Python statement normally ends at the end of the line — no semicolon needed. You can put a semicolon between two statements to fit them on one line, but it's rarely done in real code:
x = 5
y = 10
print(x + y) # normal style — one statement per linePython has one comment style, #, for single-line comments. Multi-line comments aren't a dedicated feature, though a triple-quoted string not assigned to anything is commonly used the same way:
# This is a single-line comment
"""
This is often used as a multi-line comment,
even though it's technically just an unused string.
"""print() is Python's equivalent of PHP's echo — the standard way to output text. Unlike echo, it's a real function, always called with parentheses:
print("Hello, world!")
print("Multiple", "values", "get", "joined", "with spaces")With the ground rules out of the way, the next lesson looks at how Python stores data — starting with variables.