Swap Variables
In this challenge, you'll learn how to swap the values of two variables in Python! It's a useful trick and a fun way to practice your coding skills.
Imagine you have two boxes, Box A and Box B. Box A has a toy car, and Box B has a toy train. But you wanted the car in Box B and the train in Box A! How would you make them swap places without losing any toy in the process?
In Python, swapping is easy and fun! You can use tuple unpacking to swap the values in one line.
Task
Write a function swap_variables that takes two parameters, a and b, which are the values to be swapped. The function should return a tuple (b, a).
Example
Let's see some examples:
swap_variables(1, 2) # Output: (2, 1) swap_variables('apple', 'orange') # Output: ('orange', 'apple')
Additional Fun
Try using this in real life with two cups, a pen and a pencil, or anything else you can think of that needs swapping! Have fun swapping!
Inputs
Arg 1:
1Arg 2:
2Expected Output
[2, 1]Actual Output