Concatenation in Tuple

  • Concatenation in tuples refers to the process of combining two or more tuples to create a new tuple containing all the elements from the original tuples.
  • Since tuples are immutable, concatenation does not modify the original tuples, but rather creates a new tuple with the combined elements.
  • Tuples can be combined using + operator to combine two or more tuples
# Concatenation in Tuple
int_tuple1 = (1, 2, 3)
int_tuple2 = (4, 5, 6)

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

print()

string_Tuple1 = ('a', 'b', 'c', 'd')
string_Tuple2 = ('p', 'q', 'r')
concatenated_tuple = string_Tuple1 + string_Tuple2
print(concatenated_tuple)  # Output: ('a', 'b', 'c', 'd', 'p', 'q', 'r')

Output of above code

Leave a comment