Python Practice › Tuple Programs › Program 68
Swap two tuples
Write a Python program to swap two tuple variables.
Input
A = (7, 4, 9), B = (3,)
Output
A = (3,) B = (7, 4, 9)
Approach
- Tuple unpacking swaps the names.
Solution
A, B = (7, 4, 9), (3,)A, B = B, Aprint("A =", A)print("B =", B)Output
A = (3,) B = (7, 4, 9)
Learn the concept
New to this topic? Read the lesson, then come back.