Created
August 30, 2017 18:03
-
-
Save Yunkou/3df0e463476335e29af85f99d008cbe5 to your computer and use it in GitHub Desktop.
Tuple unpacking
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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