gpt4 book ai didi

python - ,= 在 python 中是什么意思?

转载 作者:IT老高 更新时间:2023-10-28 21:47:14 28 4
gpt4 key购买 nike

我想知道 ,=,= 在 python 中是什么意思?

matplotlib 中的示例:

plot1, = ax01.plot(t,yp1,'b-')

最佳答案

这是一种元组解包形式。带括号:

(plot1,) = ax01.plot(t,yp1,'b-')

ax01.plot() 返回一个包含一个元素的元组,并将该元素分配给 plot1。如果没有那个逗号(可能还有括号),plot1 将被分配整个元组。在下面的例子中观察 ab 之间的区别:

>>> def foo():
... return (1,)
...
>>> (a,) = foo()
>>> b = foo()
>>> a
1
>>> b
(1,)

(a,)(1,) 中的括号都可以省略,为了清楚起见,我留下了它们。

关于python - ,= 在 python 中是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30601479/

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