In Python, indentation is used to define blocks of code. It tells the Python interpreter that a group of statements belongs to a specific block. All statements with the same level of indentation are considered part of the same block. Indentation is achieved using whitespace (spaces or tabs) at the beginning of each line.
For Example:
if 10 > 5:
print("This is true!")
print("I am tab indentation")
print("I have no indentation")
Output
This is true! I am tab indentation I have no indentation
- The first two print statements are indented by 4 spaces, so they belong to the if block.
- The third print statement is not indented, so it is outside the if block.