Write a Python program to Concatenate tuples to nested tuples


This program concatenates two tuples.

  • The first tuple tup1 is defined with 4 elements.
  • The second tuple tup2 is defined with 3 elements.
  • The original tuples are printed on the screen with the messages "Tuple 1" and "Tuple 2".
  • The two tuples are concatenated using the + operator and the result is stored in the variable res.
  • The final concatenated tuple is printed on the screen with the message "Tuples after Concatenating".

Note that tuples are immutable in Python, which means that their elements cannot be changed once the tuple is created. Concatenating two tuples creates a new tuple that contains all the elements of both original tuples.

Source Code

tup1 = (18 , 23 , 2 , 9),
tup2 = (10 , 3 , 11),
print("Tuple 1 : ",tup1)
print("Tuple 2 : ",tup2)
res = tup1 + tup2
print("Tuples after Concatenating : ",res)
 

Output

Tuple 1 :  ((18, 23, 2, 9),)
Tuple 2 :  ((10, 3, 11),)
Tuples after Concatenating :  ((18, 23, 2, 9), (10, 3, 11))


Example Programs