Indentation and White Space
White space is not ignored and is part of the syntax.
Blank lines are ignored, even when they are inside indented blocks.
Indentation
Indentation refers to the spaces at the beginning of a code line and is absolutely essential.
Where in other programming languages the indentation in code is for readability only, the indentation in Python is very important.
There are no curly brackets - indentation is used instead
Python uses indentation to indicate a block of code.
Python will give you an error if you skip the indentation.
Indentation - every indented block is indented by 4 spaces
def adjust_price(price: float, age: int) -> float:
if age > 60:
return price * .8
else:
return price
assert_equal(adjust_price(5.75, 63), 4.60)
assert_equal(adjust_price(5.75, 45), 5.75)
Vertical Alignment
res = function_name(var_one, var_two,
var_three, var_four)
Hanging Indent
res = function_name(
var_one, var_two,
var_three, var_four)
Additional Indentation
res = function_name(
var_one, var_two,
var_three, var_four)
print(var_one)
if(this_one
and that_one):
dosomething()
"and" is an operator and a keyword
Square Brackets
my_list = [
1, 2, 3,
4, 5, 6,
]
Parentheses
res = function_name(
'a', 'b', 'c',
)
© 2026 Better Solutions Limited. All Rights Reserved. © 2026 Better Solutions Limited TopPrevNext