In Python, indentation is the space at the start of a line that tells Python which code belongs inside a block. Start by looking at an `if` statement: its indented line runs only when the condition is true. section 13.2
Listing 13.1. Example of a simple conditional statement
num = int(input("Enter a number: ")) #1
if num > 0: #2
print("num is positive") #3
print("finished comparing num to 0") #4
The line indented four spaces prints only when `num` is positive. The final, unindented line runs afterward regardless of the number. section 13.2
Indentation also shows whether decisions are nested. Two `if` statements at the same level are checked in turn. Indent the second `if` inside the first, and Python reaches it only when the first condition is true. section 13.3
Listing 13.4. Combining conditionals by nesting or by putting them in series
Nested code Unnested code
num_a = int(input("Number? ")) num_a = int(input("Number? "))
num_b = int(input("Number? ")) num_b = int(input("Number? "))
if num_a < 0: #1 if num_a < 0: #1
print("num_a: is negative") print("num_a is negative")
if num_b < 0: #2 if num_b < 0: #2
print("num_b is negative") print("num_b is negative")
print("Finished") #3 print("Finished") #3
Compare the two versions when the first number is positive and the second is negative. Only the unnested version checks whether the second number is negative. section 13.3
A function body
In `def func_1(one, two, three):`, the indented `if` belongs to the function, and its more deeply indented `print("equal")` belongs to the `if`. The same indentation idea works with functions, loops, and conditionals. section 21.1





