Python Practice › Tuple Programs › Program 68

Swap two tuples

EasyTuple Programs · 68 of 70

Write a Python program to swap two tuple variables.

Advertisement
Input
A = (7, 4, 9), B = (3,)
Output
A = (3,)
B = (7, 4, 9)

Approach

  1. Tuple unpacking swaps the names.

Solution

Python
A, B = (7, 4, 9), (3,)A, B = B, Aprint("A =", A)print("B =", B)
Output
A = (3,)
B = (7, 4, 9)
Advertisement

Learn the concept

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

More tuple programs

← All 70 Tuple Programs