Skip to content

Instantly share code, notes, and snippets.

@ferminhg
Last active May 20, 2019 07:46
Show Gist options
  • Select an option

  • Save ferminhg/c92753eef8b295cb9d7671f662aa0e04 to your computer and use it in GitHub Desktop.

Select an option

Save ferminhg/c92753eef8b295cb9d7671f662aa0e04 to your computer and use it in GitHub Desktop.
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment