Interpreter
The Python interpreter executes the following steps:
- First, run the syntax.
- Then execute the code line by line.
- Code inside a function or class declaration is not executed (but checked for syntax).
def f(x): return y**2 a = 3 # here both a and f are defined
You can run the preceding program because there are no syntactical errors. You get an error only when you call the function f
.
f(2) # error, y is not defined