Python:为什么不(a,b,c)=(*x,3)

Mar*_*ark 7 python

显然我不能用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)

所以我要问的是

  1. 是不是有理由不允许这个?(第一件事)
  2. 什么是最接近的工作?

我目前对#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)

ely*_*ase 8

在回答问题1时,请阅读PEP 448错误2292.同样有趣的是邮件列表中的讨论.在简历中,你应该在Python 3.4中允许你想要的东西.对于问题2,请参阅其他解决方案.