Grouping statements in Python - Python Block Structure

Using the group of statements, we can achieve a complete task.

Python uses indentation mechanism to group the statements.


All statements with the same distance from the left side are considered as a group or a block.

Pictorial Explanation

python block structure

Example

print("group1")
if 1: #group1
    print("group2");
    print("group2");
    if 1: #group2
        print("group3")
        print("group3")
    print("group2-continues")
print("group1-continues")

Topics You Might Like