[Tutor] Syntax error while attempting to type in multiline statements in the interactive interpreter

boB Stepp robertvstepp at gmail.com
Sat Feb 4 17:02:02 EST 2017


py3: a
['Mary', 'had', 'a', 'little', 'lamb', 'break']
py3: for w in a:
...     print(w)
... print('Huh?')
  File "<stdin>", line 3
    print('Huh?')
        ^
SyntaxError: invalid syntax

I don't understand why this throws a SyntaxError.  If I wrap
essentially the same code into a function it works:

py3: def print_list(a_list):
...     for item in a_list:
...             print(item)
...     print('Huh?')
...
py3: print_list(a)
Mary
had
a
little
lamb
break

What am I not understanding here?

-- 
boB


More information about the Tutor mailing list