How to Join Two Tuples in Python
Learn how to join two or more tuples in Python using the +
operator. Understand how to combine different tuples into one and work with the result.
Join Two Tuples
To join two or more tuples, you can use the +
operator:
Example
tuple1 = ("dog", "cat", "rabbit")
tuple2 = (4, 5, 6)
tuple3 = tuple1 + tuple2
print(tuple3)
Output
('dog', 'cat', 'rabbit', 4, 5, 6)
Multiply Tuples
If you want to multiply the content of a tuple a given number of times, you can use the *
operator:
Example
fruits = ("orange", "grape", "mango")
mytuple = fruits * 2
print(mytuple)
Output
('orange', 'grape', 'mango', 'orange', 'grape', 'mango')