4.3.5 Tuple Packing & Unpacking

Unit: Unit 4: Strings, Lists, and Tuples • Interactive Practice

Quick Answer & Summary:

Interactive Python programming tutorial and practice in your browser.

Interactive Challenge (Run Live in Browser):

# Practice tuple packing, sequence unpacking, and variable swapping
x = 10
y = 20

# 1. Swap x and y in a single Pythonic step
x, y = y, x

# 2. Pack and unpack user profile data
user_tuple = ("dev_lead", "active", 120)
role, status, score = user_tuple

print(f"Swapped: x = {x}, y = {y}")
print(f"Role: {role} | Status: {status} | Score: {score}")
Open in Live Interactive Python Sandbox →