Python Tricks: Python’s shorthand for in-place value swapping

# Why Python Is Great:
# In-place value swapping

# Let's say we want to swap
# the values of a and b...
a = 23
b = 42

# The "classic" way to do it
# with a temporary variable:
tmp = a
a = b
b = tmp

# Python also lets us
# use this short-hand:
a, b = b, a

Leave a Reply

Your email address will not be published. Required fields are marked *