Concatenating Tuple

前端 未结 7 1246
-上瘾入骨i
-上瘾入骨i 2020-12-29 20:40

Suppose I have a list:

a=[1,2,3,4,5]  

Now I want to convert this list into a tuple. I thought coding something like this would do:

7条回答
  •  时光取名叫无心
    2020-12-29 21:43

    just a kind of precis: (2,) is actually same of tuple([2]) so you can write:

    >>>(2,) + tuple([2,3])
    (2, 2, 3)
    >>> tuple([2]) + (2,3)
    (2, 2, 3)
    >>> tuple([2]) + tuple([2,3])
    (2, 2, 3)
    

    python is very supple indeed

提交回复
热议问题