Is Python compiled or interpreted?


There are syntax errors that will prevent your Python code from running


examples/basics/syntax_error.py
x = 2
print(x)

if x > 3

File "examples/other/syntax_error.py", line 4
    if x > 3
           ^
SyntaxError: invalid syntax


There are other syntax-like errors that will be only caught during execution


examples/basics/compile.py
x = 2
print(x)
print(y)
y = 13
print(42)

2
Traceback (most recent call last):
  File "compile.py", line 5, in <module>
    print y
NameError: name 'y' is not defined


examples/basics/compile_with_global.py
def f():
    global y
    y = "hello y"
    print("in f")

x = 2
print(x)
f()
print(y)
y = 13
print(42)

2
in f
hello y
42