Skip to content

Instantly share code, notes, and snippets.

@Yunkou
Created August 30, 2017 18:03
Show Gist options
  • Save Yunkou/3df0e463476335e29af85f99d008cbe5 to your computer and use it in GitHub Desktop.
Save Yunkou/3df0e463476335e29af85f99d008cbe5 to your computer and use it in GitHub Desktop.
Tuple unpacking
# The bad way
x = 10
y = -10
print('Before: x = %d, y = %d' % (x, y))
tmp = y
y = x
x = tmp
print('After: x = %d, y = %d' % (x, y))
# The good way
x, y = 10, -10
print('Before: x = %d, y = %d' % (x, y))
x, y = y, x
print('After: x = %d, y = %d' % (x, y))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment