简体   繁体   中英

Python: adding element to tuple

i have google searched for hours but still not able to find a solution.

x = ((1, 2), (3, 4))
y = 5.0

Is that possible to convert to the tuple format below?

(((1, 2), 5.0), (3, 4))

Edit: Solved. Thanks all.

Tuples are immutable. But they do support indexing, so you can easily create a new one:

x = ((x[0], y), x[1])

# (((1, 2), 5.0), (3, 4))

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