How to Define Scope in Code Relying On Indentation in Python


In this example, we will learn how to define the scope in the code relying on indentation (whitespace at the beginning of a line) in Python.

Source Code

x = 20
y = 8
if x > y:
print('x is greater than y')    # you will get an error

Output:

  File "demo.py", line 4
    print('x is greater than y')
        ^
IndentationError: expected an indented block

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
Advertisement