operators - What does ,= mean in python? -
i wonder ,=
or , =
means in python?
example matplotlib:
plot1, = ax01.plot(t,yp1,'b-')
it's form of tuple unpacking. parentheses:
(plot1,) = ax01.plot(t,yp1,'b-')
ax01.plot()
returns tuple containing 1 element, , element assigned plot1
. without comma (and possibly parentheses), plot1
have been assigned whole tuple. observe difference between a
, b
in following example:
>>> def foo(): ... return (1,) ... >>> (a,) = foo() >>> b = foo() >>> 1 >>> b (1,)
you can omit parentheses both in (a,)
, (1,)
, left them sake of clarity.
Comments
Post a Comment