When you want to swap the values of the variable ʻa: 100and the variableb: 20, you usually create the variable c, hold the value of ʻa in c, and then say ʻa. Swap the values of b`.
swap.py
a = 100
b = 20
easy_swap.py
#Multiple assignment
a, b = 100,20
#Value exchange
a, b = b, a
By the way, Ruby can do the same.
Recommended Posts