mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2025-08-13 18:24:39 +02:00
Merge pull request #1928 from TheRakken/TheRakken-patch-1
[python] Updated tuple examples for clarity
This commit is contained in:
@@ -261,8 +261,9 @@ tup[:2] # => (1, 2)
|
|||||||
|
|
||||||
# You can unpack tuples (or lists) into variables
|
# You can unpack tuples (or lists) into variables
|
||||||
a, b, c = (1, 2, 3) # a is now 1, b is now 2 and c is now 3
|
a, b, c = (1, 2, 3) # a is now 1, b is now 2 and c is now 3
|
||||||
|
d, e, f = 4, 5, 6 # you can leave out the parentheses
|
||||||
# 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
|
g = 4, 5, 6 # => (4, 5, 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
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user