Variables in Python may be used before they are set. This will generate a runtime error, not a syntax error. Here's an example using local variables:
>>> def f():
... return a
... a = 3
...
>>> f()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 2, in f
UnboundLocalError: local variable 'a' referenced before assignment
This is in contrast to languages which consider dereferencing an unassigned or undefined variable a syntax error. Python doesn't "capture" the current state of lexical scope, it just uses references to mutable lexical scopes. Here's a demonstration:
>>> def f(): return a
...
>>> f()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 1, in f
NameError: global name 'a' is not defined
>>> a = 3
>>> f()
3