Syntax & Indentation
Python looks different from languages like C, Java or PHP the moment you see it, because it has no curly braces { } to mark the start and end of a block of code. Instead, Python uses indentation (whitespace at the start of a line) to decide what belongs inside a block. Getting comfortable with this rule is the very first step to writing correct Python.
Indentation Defines Blocks
Every statement that belongs inside an if, a loop, a function, or a class must be indented by the same amount, conventionally 4 spaces. There is no closing brace; the block simply ends when the indentation goes back to the previous level.
if 5 > 2:
print("Five is greater than two!")
print("This line is also inside the if block.")
print("This line is outside the if block.")
Both print() calls indented by 4 spaces run only when the condition is true; they are part of the if block. The final print(), back at column zero, always runs because it sits outside the block.
Getting Indentation Wrong
Because indentation is meaningful, using an inconsistent number of spaces inside the same block is not just a style issue — it is a syntax error. Mixing indentation levels like below raises an IndentationError:
if 5 > 2:
print("First line, 4 spaces")
print("Second line, only 3 spaces")
# IndentationError: unindent does not match any outer indentation level
Note: Never mix tabs and spaces in the same file. Most editors, including VS Code and PyCharm, can be configured to insert 4 spaces automatically whenever you press Tab, which avoids this problem entirely.
Comments
A single-line comment starts with #; everything from the # to the end of the line is ignored by Python.
# this entire line is a comment
print("Hello") # this part is a comment too
Python has no dedicated multi-line comment syntax, but a triple-quoted string that is not assigned to anything and not used as a value is simply evaluated and discarded, so it is commonly used to comment out several lines at once:
"""
This is often used as a multi-line comment.
It can span as many lines as needed.
"""
print("Code continues here")
Case Sensitivity
Python is case sensitive. age, Age and AGE are three completely different variable names.
age = 25
Age = 30
print(age) # 25
print(Age) # 30
Statement Termination
Unlike C, Java or PHP, Python statements do not need a semicolon at the end. Each new line is treated as a new statement by default.
x = 5
y = 10
print(x + y)
It is possible to place multiple statements on a single line by separating them with a semicolon, but this is considered poor style and hurts readability, so it should be avoided in normal code:
# works, but discouraged
x = 5; y = 10; print(x + y)
The print() Function
The standard way to display output in Python is the built-in print() function. It accepts one or more values, which can be text, numbers, or other expressions.
print("Hello, World!")
print(42)
print("The answer is", 42)