【问题标题】:Python3: You cannot use a Python keyword as a function namePython3:不能使用 Python 关键字作为函数名
【发布时间】:2021-02-06 21:45:36
【问题描述】:

在处理 python 脚本时,我在将代码拆分为函数时遇到了 SyntaxError 代码:

def pass():
    print("Sol")

错误

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 是关键字,请选择其他名称。

标签: python python-3.x exception


【解决方案1】:

pass是python中的keyword——它有python定义的特殊含义。因此,您不能使用“pass”作为函数名。只需将函数名称更改为其他名称(不在 python 关键字列表中...)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-02
    • 2017-01-15
    • 2018-12-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多