Skip to content

Instantly share code, notes, and snippets.

@bolerap
Created November 3, 2016 04:16
Show Gist options
  • Save bolerap/4c11f8cb2d77547dc7d1344ffc720e2e to your computer and use it in GitHub Desktop.
Save bolerap/4c11f8cb2d77547dc7d1344ffc720e2e to your computer and use it in GitHub Desktop.
# 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