mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2024-10-05 00:58:17 +03:00
parent
764d30947b
commit
30cdf4b253
@ -281,7 +281,8 @@ a, b, c = (1, 2, 3) # a is now 1, b is now 2 and c is now 3
|
|||||||
# You can also do extended unpacking
|
# You can also do extended unpacking
|
||||||
a, *b, c = (1, 2, 3, 4) # a is now 1, b is now [2, 3] and c is now 4
|
a, *b, c = (1, 2, 3, 4) # a is now 1, b is now [2, 3] and c is now 4
|
||||||
# Tuples are created by default if you leave out the parentheses
|
# Tuples are created by default if you leave out the parentheses
|
||||||
d, e, f = 4, 5, 6
|
d, e, f = 4, 5, 6 # tuple 4, 5, 6 is unpacked into variables d, e and f
|
||||||
|
# respectively such that d = 4, e = 5 and f = 6
|
||||||
# Now look how easy it is to swap two values
|
# Now look how easy it is to swap two values
|
||||||
e, d = d, e # d is now 5 and e is now 4
|
e, d = d, e # d is now 5 and e is now 4
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user