3 ms·
The file: def foo(): bar = 3 print ('4') runs fine when called as a file but when pasted into Python's REPL results in an error: >>> def foo():
by compressedgas 4y ago
The file:
def foo():
bar = 3
print ('4')
runs fine when called as a file but when pasted into Python's REPL results in an error:
>>> def foo():
... bar = 3
... print ('4')
File "<stdin>", line 3
print ('4')
^
SyntaxError: invalid syntax
However with a blank line after the definition
def foo():
bar = 3
print ('4')
results in:
>>> def foo():
... bar = 3
...
>>> print ('4')
4
- mixmastamyk 4y agoI see now. The issue was pasting the snippet into a terminal added an extra level of indentation from the post (pre must be indented). This changed the result.