REPL peculiarity

Rob Cliffe rob.cliffe at btinternet.com
Thu Mar 11 06:01:18 EST 2021


This is a valid Python program:

def f(): pass
print(f)

But at the REPL:

 >>> def f(): pass
... print(f)
   File "<stdin>", line 2
     print(f)
     ^
SyntaxError: invalid syntax

It doesn't seem to matter what the second line is.  In the REPL you have 
to leave a blank line after the "def" line.  Why?
Tested am using Python 3.8.3 and 2.7.18.

Rob Cliffe


More information about the Python-list mailing list