What is a top-level statement in Python? -


in python guide's chapter on project structure, term "top-level statement" brought few times. i'm not sure refers to. guess it's variable declarations happen outside of functions or class methods fire module loaded. correct? include module's import statements?

it's not variable declarations (and there aren't variable declarations anyway). it's pretty starts @ 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, executes part of if statement                    # top-level  class toplevel(object): # top-level     x = 3          # not top-level, executes part of class statement     def foo(self): # not top-level, executes part of class statement         print 5    # not top-level 

Comments

Popular posts from this blog

PySide and Qt Properties: Connecting signals from Python to QML -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

scala - 'wrong top statement declaration' when using slick in IntelliJ -