简体   繁体   English

Python3:您不能使用 Python 关键字作为 function 名称

[英]Python3: You cannot use a Python keyword as a function name

While working on a python script I got a SyntaxError while splitting my code into functions code:在处理 python 脚本时,我在将代码拆分为函数代码时遇到了 SyntaxError:

def pass():
    print("Sol")

Error错误

Traceback (most recent call last):
  File "TESTS:\syntax\raise_syntax_error21.py", line 1
    def pass():
        ^
SyntaxError: invalid syntax

    You cannot use a Python keyword as a function name.

A `SyntaxError` occurs when Python cannot understand your code.

pass is a keyword in python - it has a special meaning defined by python. pass是 python 中的关键字- 它具有由 python 定义的特殊含义。 Because of that, you can't use "pass" as a function name.因此,您不能使用“pass”作为 function 名称。 Just change the name of your function to something else (not in the list of python keywords...).只需将 function 的名称更改为其他名称(不在 python 关键字列表中......)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM