# Two variables with initial values
a = 10
b = 20
# Swap values using tuple unpacking
a, b = b, a
# Display the swapped values
print('After swapping:')
print('a:', a) # Output: 20
print('b:', b) # Output: 10
code
Python Swap Values using Tuple Unpacking
This Python code demonstrates how to swap the values of two variables using tuple unpacking. The a, b = b, a line efficiently swaps the values of a and b without using a temporary variable. The comments provide explanations for each part of the code.
Swap Values
Tuple Unpacking