Python SyntaxError : invalid syntax, python3 中的函数参数是否允许使用括号?

标签 python python-3.x python-2.x

该函数适用于 python2:

def setCellValue(self, (x, y), value):
    self.map[x][y] = value

但是当我在 python3 中尝试时,它显示了无效的语法:

def setCellValue(self, (x, y), value):
                            ^
SyntaxError: invalid syntax

是支架的问题吗?我如何在 py3 中解决这个问题?

最佳答案

是的,在 python3 中删除了元组解包。根据PEP 3113 :

The example function at the beginning of this PEP could easily be rewritten as:

def fxn(a, b_c, d):
    b, c = b_c
    pass 

and in no way lose functionality.

它的存在只会使语法和字节码生成变得复杂,因此被删除了。

关于Python SyntaxError : invalid syntax, python3 中的函数参数是否允许使用括号?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46616128/

相关文章:

python - 使用 beautifulsoup 抓取公交车站网页

python - 如何使用封闭类的类型键入提示方法?

python - 使用 Python 使用 JSON 或 pickle 编码为变量

python - 不一致的页面在 Internet Explorer 中显示过期消息

python - subprocess.Popen 和相关目录

python-3.x - 在哪里可以找到 PyQt5 方法签名?

performance - 为什么 `pickle.dump` +`pickle.load` IPC 这么慢,还有快速的替代方案吗?

python - Python 教程 - 我应该使用 2.x 还是 3.0?

python - 什么是查找重复对象的好 pythonic 方法?

python - WTForms 如何使用 DecimalField 在错误输入时生成正确的字段错误