摆脱 SyntaxError:Python 中的无效语法 [英] Get Rid of SyntaxError: invalid syntax in Python
本文介绍了摆脱 SyntaxError:Python 中的无效语法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
def success(self, input1: str = "", input2: str = "", input3: str = "") -> None:
E ^
E SyntaxError: invalid syntax
不知道这里发生了什么..
No idea what is happening here..
代码:
def success(self, input1: str = "", input2: str = "", input3: str = "") -> None:
input1 = str(input1)
input2 = str(input2)
input3 = str(input3)
print(Color.BOLD + Color.GREEN + " " + Color.CHECKMARK + " " + input1 + Color.END + " " + input2 + " " + input3)
推荐答案
您发布的函数是有效的 Python 3.7.类型提示被添加到 Python 3.5.0 版,你的代码发布应该适用于 3.5.0 以后的任何版本:
The function you posted is valid Python 3.7. Type hints were added to Python in version 3.5.0, the code you posted should work in any version from 3.5.0 onwards:
Python 3.7.0 (default, Aug 22 2018, 20:50:05)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> def success(self, input1: str = "", input2: str = "", input3: str = "") -> None:
... input1 = str(input1)
... input2 = str(input2)
... input3 = str(input3)
... print(Color.BOLD + Color.GREEN + " " + Color.CHECKMARK + " " + input1 +
Color.END + " " + input2 + " " + input3)
...
>>> success
<function success at 0x7fb70e4c61e0>
我怀疑您使用的是不支持这些语言功能的旧版 python.
I suspect you are using an older python version that does not support these language features.
这篇关于摆脱 SyntaxError:Python 中的无效语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文