Last active
June 20, 2016 01:50
-
-
Save Sonophoto/602a923274a900fd5d49de69756e2c43 to your computer and use it in GitHub Desktop.
The infamous python comma
This file contains hidden or 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
so a C programmer sees: | |
a, b=b, a | |
and thinks: | |
(a), (b=b), (a) | |
and wonders WTF? | |
but python thinks: | |
(a,b) = (b,a) | |
and swaps a and b with no more effort and no intermediate... | |
WHY? Because in Python, COMMA is NOT AN OPERATOR | |
comma is just a seperator and has no magic. | |
specifically it seperates things into tuples... | |
ALSO! it should be written a,b = b,a but python doesn't | |
see the whitespace either... | |
a,b,c,d = d,c,b,a works too, very cool! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment