[英]Python function on the command line not working
考慮一下這個簡單的python:
def cube(x):
return x*x*x;
if __name__ == '__main__':
print(cube(4));
工作正常。 但是,當我打開python命令行解釋器並執行:
>>> def cube(x): return x*x*x;
... cube(4);
我明白了:
File "<stdin>", line 2
cube(4);
^
SyntaxEror: invalid syntax
我做錯了什么蠢事?
再次按下輸入:) cube(4)
前面的橢圓cube(4)
表示您仍在定義您的功能。 此外,您可以刪除分號:
>>> def cube(x): return x*x*x
...
>>> cube(4)
64
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.