gpt4 book ai didi

Why Python version 3.10 does not support starred expressions in subscriptions(为什么Python 3.10版本不支持订阅中的星形表达式)

转载 作者:bug小助手 更新时间:2023-10-22 13:50:57 29 4
gpt4 key购买 nike



for example

例如


import numpy as np
a = np.ones([1, 2, 3])
b = 1, 2

In Python 3.10 I cannot use a[0,*b] It has to be a[(0,*b)] And I can use c = [0,*b] a[*c] which is a[0,1,2]

在Python 3.10中,我不能使用a[0],*b]它必须是a[(0,*b)],我可以使用c=[0],*b]a[*c],它是[0,1,2]


I find it has been changed on Python 3.11 so I can use it.

我发现它在Python 3.11上已经更改了,所以我可以使用它。


更多回答

Not supporting some syntax isn't a bug.

不支持某些语法不是错误。

@user2357112 OK, I will change the expression if you do not like it.

@user2357112好的,如果你不喜欢这个表达式,我会更改它。

优秀答案推荐

This change is a part of PEP-646 and it's described here: https://peps.python.org/pep-0646/#change-1-star-expressions-in-indexes

此更改是PEP-646的一部分,在此进行描述:https://peps.python.org/pep-0646/#change-1-star-pressions-in-indexes


And the syntax with parentheses, as you showed, was allowed before.

如您所示,带有括号的语法以前是允许的。


更多回答

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com