Interpreter

The Python interpreter executes the following steps:

  • First, run the syntax.
  • Then execute the code line by line.
  • Code inside a function or class declaration is not executed (but checked for syntax).
      def f(x):
          return y**2  
      a = 3   # here both a and f are defined

You can run the preceding program because there are no syntactical errors. You get an error only when you call the function f.

f(2) # error, y is not defined

Get Scientific Computing with Python 3 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.