Skip to content

Instantly share code, notes, and snippets.

@Sonophoto
Last active June 20, 2016 01:50
Show Gist options
  • Save Sonophoto/602a923274a900fd5d49de69756e2c43 to your computer and use it in GitHub Desktop.
Save Sonophoto/602a923274a900fd5d49de69756e2c43 to your computer and use it in GitHub Desktop.
The infamous python comma
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