Join Two Tuples
To join two or more tuples you can use the +
operator:
Example
Join two tuples:tuple1 = (“a”, “b” , “c”)
tuple2 = (1, 2, 3)
tuple3 = tuple1 + tuple2
print(tuple3)
Output:
(‘a’, ‘b’, ‘c’, 1, 2, 3)
Multiply Tuples
If you want to multiply the content of a tuple a given number of times, you can use the *
operator:
Example
Multiply the fruits tuple by 2:
fruits = (“apple”, “banana”, “cherry”)
mytuple = fruits * 2
print(mytuple)
Output:
(‘apple’, ‘banana’, ‘cherry’, ‘apple’, ‘banana’, ‘cherry’)