0
>>> def f(x):
...     print x
... f('hello')
  File "<stdin>", line 3
    f('hello')
    ^
SyntaxError: invalid syntax
>>> 

I'm at the prompt in the Python shell. Why doesn't the above code work?

2 Answers 2

5

Enter a blank line after "print x". Generally, the ... prompt indicates that Python expects further input for the current block, in this case the function f.

As pointed out by Iguananaut IPython has superior editing capabilities compared to the standard Python shell, for example tab auto completion.

Sign up to request clarification or add additional context in comments.

Comments

2

You need to press enter twice after the last line to get back to a >>> prompt in which case you can enter new expressions.

Also, if you're going to by typing lots of multi-line expressions into the interpreter you should give IPython (now with funding!) a look. It supports much better editing of multi-line statements, and even better still if you use the qtconsole or the notebook.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.