Exercise: Swap Two Variables¶
Write a program
swap.py
that exchanges (swaps) two variablesvar1
andvar2
, bothstr
type.To output the values before and after the swap operation, use the
print()
function.var1 = 1 var2 = 2 print('Before:', var1, var2) # let the miracle happen: exchange the two variables! print('After:', var1, var2)
Once the miracle took place, the output of the program should look like follows:
$ python swap.py Before: 1 2 After: 2 1