print and assignment

Assignment

#可同时(并行)给多个变量赋值
x, y, z = 1, 2, 3 

#交换多个变量的值
 x, y = y, x 

Unpacking sequence (or iterables unpack): one sequence (or any iterables) unpacked, and the resulting value is stored in a series of variables

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

Operator asterisk (*) to collect the excess value,

>>> a, b, *rest = [1, 2, 3, 4]
>>> rest
[3, 4] 

Chain assignment

x = y = someFunction ()

Guess you like

Origin www.cnblogs.com/g2thend/p/12093979.html