Python Practice › Tuple Programs › Program 62
Concatenate or nest two tuples
Write a Python program to concatenate two tuples, and to nest them inside one tuple.
Input
("s", "q", "a"), ("t", "o", "o", "l")Output
('s', 'q', 'a', 't', 'o', 'o', 'l')
(('s', 'q', 'a'), ('t', 'o', 'o', 'l'))Approach
+joins;(a, b)nests.
Solution
a = ("s", "q", "a")b = ("t", "o", "o", "l")print(a + b)print((a, b))Output
('s', 'q', 'a', 't', 'o', 'o', 'l')
(('s', 'q', 'a'), ('t', 'o', 'o', 'l'))Learn the concept
New to this topic? Read the lesson, then come back.