Python Practice › Tuple Programs › Program 62

Concatenate or nest two tuples

EasyTuple Programs · 62 of 70

Write a Python program to concatenate two tuples, and to nest them inside one tuple.

Advertisement
Input
("s", "q", "a"), ("t", "o", "o", "l")
Output
('s', 'q', 'a', 't', 'o', 'o', 'l')
(('s', 'q', 'a'), ('t', 'o', 'o', 'l'))

Approach

  1. + joins; (a, b) nests.

Solution

Python
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'))
Advertisement

Learn the concept

New to this topic? Read the lesson, then come back.

More tuple programs

← All 70 Tuple Programs