python 赋值魔法

 序列解包:

>>> x,y,z = 1, 2, 3
>>> print(x, y, z)
1 2 3

 

>>> a,b, *reset = [1,2,3,4]
>>> print(a,b,reset)
1 2 [3, 4]

 

链式赋值:

 x = y = function

 

增量赋值:

>>> x = 2
>>> x +=1
>>> x
3
>>> x *=2
>>> x
6

>>> fnord = 'foo'
>>> fnord +='bar'
>>> fnord
'foobar'
>>> fnord *=2
>>> fnord
'foobarfoobar'

 

posted @ 2019-06-24 17:09  嵌入式实操  阅读(170)  评论(0编辑  收藏  举报