Account
Categories

Python Tuple Concatenation (+)


Definition

It combines the data from two or more tuples into a new tuple using the plus (+) concatenation operator.

Now you will clearly understand the operation through the flowchart.

a = (1, 2)
b = (3, 4)

a ───► (1, 2)
                \
                 +  →  (1, 2, 3, 4)
                /
b ───► (3, 4)

Result →  (1, 2, 3, 4)

Syntax:

result = tuple1 + tuple2

Example:

a = (1, 2)
b = (3, 4)
print(a + b)

Output:

Exercise

Create two tuples a = (5, 6) and b = (7, 8) and combine them using concatenation.