On 3/11/2021 6:01 AM, Rob Cliffe via Python-list wrote:
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?

REPL executes *one* statement at a time. It has always required a blank to end a compound statement because ending with a dedented second statement violates that.

Something like
>>> def f():
...      a = 3

is more typical. A dedented statement looks like a buggy continuation line.

--
Terry Jan Reedy


--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to