Created
November 3, 2016 04:16
-
-
Save bolerap/4c11f8cb2d77547dc7d1344ffc720e2e to your computer and use it in GitHub Desktop.
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
# 1 | |
a, b, c = 1, 2, 3 | |
d = a, b, c | |
print(d, type(d)) # (1, 2, 3) tuple | |
# 2 | |
a, b, c = (2 * i + 1 for i in range(3)) | |
d = a, b, c | |
print(d) # (1, 3, 5) | |
# 3 | |
a, (b, c), d = [1, (2, 3), 5] | |
print(a, b, c, d) # 1 2 3 5 | |
# 4 - Swapping variables | |
a, b = 1, 2 | |
a, b = b, a | |
print(a, b) # 2 1 | |
# 5 Extend unpacking (python 3 only) | |
a, b, *c = [1, 2, 3, 4, 5] | |
print(a, b, c) # 1, 2, [3, 4, 5] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment