python-3.x - Python 嵌套括号函数参数列表语法无效

标签 python-3.x

页面代码chaotic attractor reconstruction.在 Python 3.4.4 下运行时返回错误如下:

SyntaxError: invalid syntax

在函数参数部分的第二个左括号处:

def rossler_odes((x, y, z), (a, b, c)):
    return numpy.array([-y - z, x + a * y, b + z * (x - c)])

我猜这可能是 Python 版本问题,例如为早于 3.4.4 的版本创建的代码。我不懂 Python,但我希望运行它来学习物理,当然还有语言。

最佳答案

元组参数解包已在 Python 3 中删除,请参阅 PEP 3113 , 还有 What's new in Python 3.0 .正如那里所建议的那样,使代码与 Python 2/3 兼容的最简单方法是使用

def rossler_odes(x_y_z, a_b_c):
    x, y, z = x_y_z
    a, b, c = a_b_c
    return numpy.array([-y - z, x + a * y, b + z * (x - c)])

关于python-3.x - Python 嵌套括号函数参数列表语法无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34916569/

相关文章:

python-3.x - 给视频添加水印

python - 删除数据框中的行数

python - 运行时的方法替换不更新私有(private)属性

python-3.x - 来自part()的部分分数

python - 如何对列表进行切片以在新列表中获取列表的每 2 个连续元素?

python - python 字符串格式错误

Python:将函数参数的默认值传递给 *args 或 **kwargs

python-3.x - python 3 pyinstaller 始终给出 "failed to create process"

python - 列表中 10 的倍数

python - 尝试在多线程中处理链接时出错