I have a tuple:
a = (1,2,3)
and I need to add a tuple at the end
b = (4,5)
The result should be:
(1,2,3,(4,5))
Even if I wrap b in extra parents: a + (b), I get (1,2,3,4,5) which is not what I wanted.
When you do a + b
you are simply concatenating both the tuples. Here, you want the entire tuple to be a part of another tuple. So, we wrap that inside another tuple.
a, b = (1, 2, 3), (4,5)
print a + (b,) # (1, 2, 3, (4, 5))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With