Skip to content

Instantly share code, notes, and snippets.

@petergi
Created April 8, 2026 15:18
Show Gist options
  • Select an option

  • Save petergi/3bf5cf3570cb8d6ff761e6f69a2fa831 to your computer and use it in GitHub Desktop.

Select an option

Save petergi/3bf5cf3570cb8d6ff761e6f69a2fa831 to your computer and use it in GitHub Desktop.
# 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