In the Python Guide\'s chapter on project structure, the term \"top-level statement\" is brought up a few times. I\'m not sure exactly what this refers to. My guess is it\'s any
It's not just variable declarations (and there aren't any variable declarations anyway). It's pretty much anything that starts at indentation level 0.
import sys # top-level
3 + 4 # top-level
x = 0 # top-level
def f(): # top-level
import os # not top-level!
return 3 # not top-level
if x: # top-level
print 3 # not top-level
else:
print 4 # not top-level, but executes as part of an if statement
# that is top-level
class TopLevel(object): # top-level
x = 3 # not top-level, but executes as part of the class statement
def foo(self): # not top-level, but executes as part of the class statement
print 5 # not top-level