I'm fairly new to Python and would like to know, how exactly does Python run it's code ? Now, for an interpreted language it would make sense if the following code:
print("Hello, World!")
def foo
print('foo')
Would print the 'Hello, World!' and then stop the execution, because there is a syntax error on the next line (missing ':'). However, the line will not be printed at all:
The output:
File "test.py", line 2
def foo
^
But the next piece of code will print 'Hello, World!' and stop the execution at the 4th line.
print("Hello, World!")
hans = 3
peter = 0
joseph = hans / peter
The output:
Hello, World!
Traceback (most recent call last):
File "test.py", line 4, in <module>
jospeh = hans / peter
ZeroDivisionError: division by zero
I know about syntax and logic types of code errors but does python interpreter care about the next line of code at all ?
I am looking forward to any contributions! Thank you!