打包
如给出一系列由逗号分隔的表达式,他们将被视为一个单独元组,即使没有提供封闭的圆括号
如:
numbers = 1, 2, 3, 4 |
return a, b |
a, b, c, d = range(1,5) |
quotient, remainder = divmod(a, b) |
for x, y in[(1, 2), (3, 4), (5, 6)]: |
for key, value in dict.items(): |
同时分配
同时分配为打包和解包的结合,如:
x, y, z = 1, 2, 3 |
a, b = b, a |
def fibonacci(): a, b = 0, 1 while True: yield a a, b = b, a+b |