[英]interactive Shell print function showing SyntaxError: invalid syntax
Hello everyone I was working on a exercise and also new to the syntax of the use of python.大家好,我正在做一个练习,也是 Python 使用语法的新手。 I tried to write this code to show the Max Number:
我尝试编写此代码以显示最大数量:
def maxNum(a,c):
if a>c:
return a
else:
return c
print(maxNum(16,20))
a little background when I use maxNum(16,20)
or print(maxNum(16,20))
I get a SyntaxError: invalid syntax in the interactive shell however when I use a new window and run the above script the answer 20 is shown.当我使用
maxNum(16,20)
或print(maxNum(16,20))
时的一点背景我得到一个 SyntaxError: invalid syntax in the interactive shell 但是当我使用一个新窗口并运行上面的脚本时,会显示答案 20 . Why is it the above script has to be ran from a new window and not in the shell it to work?为什么上面的脚本必须从新窗口运行而不是在 shell 中运行? In addition is there a website that shows when or how to indent?
此外,是否有网站显示何时或如何缩进? Thanks
谢谢
You have extra spaces on the apparently empty line between the end of the function definition and the print
call.在函数定义的结尾和
print
调用之间的明显空行上有额外的空格。 With that, the interpreter is expecting more content in the function.有了这个,解释器期望函数中有更多的内容。 To end a compound statement in an interactive session, you need two linefeeds in a row.
要在交互式会话中结束复合语句,您需要连续使用两个换行符。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.