Python Tuple Operations: Concatenation, Repetition, Unpacking

Here are 3 basic tuple operations.

Concatenation

You can concatenate two or more tuples using the + operator.

tuple1 = (1, 2, 3)
tuple2 = (4, 5, 6)
concatenated_tuple = tuple1 + tuple2
print(concatenated_tuple)  # Output: (1, 2, 3, 4, 5, 6)

Repetition

Tuples can be repeated by using the * operator.

tuple1 = (1, 2)
repeated_tuple = tuple1 * 3
print(repeated_tuple)  # Output: (1, 2, 1, 2, 1, 2)

Unpacking

Tuple unpacking allows assigning individual elements to multiple variables

my_tuple = (1, 2, 3)
a, b, c = my_tuple
print(a, b, c)  # Output: 1 2 3