将元组附加到元组

Har*_*rdy 6 python tuples append

我可以为元组添加值

>>> x = (1,2,3,4,5)
>>> x += (8,9)
>>> x
(1, 2, 3, 4, 5, 8, 9)
Run Code Online (Sandbox Code Playgroud)

但是我怎样才能将元组添加到元组中

>>> x = ((1,2), (3,4), (5,6))
>>> x
((1, 2), (3, 4), (5, 6))
>>> x += (8,9)
>>> x
((1, 2), (3, 4), (5, 6), 8, 9)
>>> x += ((0,0))
>>> x
((1, 2), (3, 4), (5, 6), 8, 9, 0, 0)
Run Code Online (Sandbox Code Playgroud)

我怎么能做到

((1,2),(3,4),(5,6),(8,9),(0,0))

Ama*_*dan 10

x + ((0,0),)
Run Code Online (Sandbox Code Playgroud)

应该给你

((1, 2), (3, 4), (5, 6), (8, 9), (0, 0))
Run Code Online (Sandbox Code Playgroud)

Python对于单元素元组有一个不可思议的语法:(x,)它显然不能只使用(x),因为它只是x在括号中,因此是奇怪的语法.使用((0, 0),),我将你的4元组对与1元组结对,而不是你所拥有的2元组整数(0, 0).