简体   繁体   中英

Tuple unpack in assignment

I would like to unpack a tuple in a python statement like so:

a = 5, *(6,7)

but this raises a SyntaxError . What is the cleanest way to achieve something like this?

The best I've come up with so far is:

a = tuple([5]+list((6,7)))

You can just concatenate the tuples directly:

>>> a = (5,)+(6, 7)     
>>> a
(5, 6, 7)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM