Tuples in python can be nested.
If simply add one tuple to another through the concatenation operation “+”, python will merge the values of the tuples:
1 2 3 4 5 6 7 8 |
a = ((1, 2), (3, 4)) print(a) # ((1, 2), (3, 4)) b = (5, 6) print(b) # (5, 6) a += b print(a) # ((1, 2), (3, 4), 5, 6) |
In order an added tuple to become nested, put a comma “,” after an added tuple:
1 2 |
a += b, print(a) # ((1, 2), (3, 4), (5, 6)) |