Python Indentation

Louis SanchezJanuary 20th 2021, 8:42

A block is a group of statements that are meant to be executed together. In Python, statements are grouped using whitespace, that is, blocks are indented within other blocks instead of using curly braces.

if True:

    # execute this block of statements
    
    print("Block 1")
    
else:
    
    # execute other block of statements
    
    print("Block 2")

If statement, without indentation (will raise an error):

if True:

# execute this block of statements
    
print("Block 1")
    
else:
    
# execute other block of statements
    
print("Block 2")