显然我不能用Python(2.7)做到这一点:
x = (1, 2,)
(a, b, c) = (*x, 3)
Run Code Online (Sandbox Code Playgroud)
它在我的头脑中是有道理的,但是......我可以创建一个函数:
make_tuple = lambda *elements: tuple(elements)
Run Code Online (Sandbox Code Playgroud)
那我就能做到
(c, a, b) = make_tuple(3, *x)
Run Code Online (Sandbox Code Playgroud)
但不是,例如
(a, b, c) = make_tuple(*x, 3)
(a, b, c, d) = make_tuple(*x, *x)
y = [3, 4]
(a, b, c, d) = (*x, *y,)
Run Code Online (Sandbox Code Playgroud)
所以我要问的是
我目前对#2的猜测:
(a, b, c) = x + (3,)
(a, b, c, d) = x + x
(a, b, c, d) = x + tuple(y)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
683 次 |
| 最近记录: |