0

I just finished watching this video https://www.youtube.com/watch?v=qO4ZN5uZSVg, and even though it teaches 2.0 edition Python, some notes pop up for the 3.0 uses of python. Nevertheless, in the end, some challenges are provided, one of them is this:

def returnTwo():
    return 20,30
x,y = returnTwo()
print(x,y)

Whenever i try to see what the conclusion will be, this is what comes up

def returnTwo():
    return 20,30
(red X in the 3.5 Shell) x,y = returnTwo()
SyntaxError: invalid syntax.

What can I do?

sfjac
  • 7,119
  • 5
  • 45
  • 69
csnoob
  • 97
  • 1
  • 9
  • 3
    Did you type enter before entering `x,y = returnTwo()`? In the python shell, three dots denote that what you are currently typing is still part of the function definition. In this case, maybe the shell interpreted the statement `x,y = returnTwo` as part of the function definition. – helios35 Nov 01 '15 at 14:36
  • This is what i type. def returnTwo(): *enter* return 20,30 *enter*(starts from the beggining of the line and not under the return 20,30) x,y = returnTwo() *enter* and i get this SyntaxError: invalid syntax , while the x in the x,y=returnTwo is highlited in red color – csnoob Nov 01 '15 at 14:38
  • As is, this has no Syntax Error. Are you **sure** this is the code you ran? – Dimitris Fasarakis Hilliard Nov 01 '15 at 14:38
  • http://prntscr.com/8xsgpk , how i see it. – csnoob Nov 01 '15 at 14:39
  • 2
    try pressing enter twice until the `>>>` re-appears. – Dimitris Fasarakis Hilliard Nov 01 '15 at 14:40
  • 2
    You most likely need another after the `return 20,30` line so that you get the prompt again before you enter `x,y=returnTwo()` – jpw Nov 01 '15 at 14:40
  • 1
    For a good tutorial (in my opinion) see http://learnpythonthehardway.org – jpw Nov 01 '15 at 14:41
  • 1
    That worked http://prntscr.com/8xsioc . Thanks a lot! – csnoob Nov 01 '15 at 14:44

1 Answers1

0

The python shell allows to interactively run commands. This is very useful when doing quick calculations of to quickly check some small pieces of code.

In this case, you want to define a function. Defining a function is just that: a definition. Later on, you actually call the function and make it run. The issue here is that a function is (often) defined in more than one line. That means, you actually hit enter before you finish to define the function. For that reason, you tell the shell that you finished with an extra enter:

enter image description here

This also applies if you define your function in a single line:

enter image description here

And that's the reason why you get a SyntaxError: The line x, y = returnTwo() is supposed to be in the function, but for that, it would need to indented (to the level of return 20, 30):

enter image description here

Like @jim said, just try pressing enter until you get the >>> prompt again!


Remember that the three little dots do have a meaning too.


This question was already answered in the comments by @helios35 and @jim!

I just elaborate and post as an answer here for future users.

Luis
  • 3,327
  • 6
  • 35
  • 62