Python function on command line not working

Consider this simple python:

def cube(x): return x*x*x; if __name__ == '__main__': print(cube(4)); 

Works fine. But when I open the python command line interpreter and do:

 >>> def cube(x): return x*x*x; ... cube(4); 

I get:

 File "<stdin>", line 2 cube(4); ^ SyntaxEror: invalid syntax 

What nonsense am I doing wrong?

+4
source share
1 answer

Try to click one more time :) The ellipse in front of your cube(4) indicates that you are still defining your function. Alternatively, you can remove the semicolon:

 >>> def cube(x): return x*x*x ... >>> cube(4) 64 
+10
source

Source: https://habr.com/ru/post/1444432/


All Articles