File tree 1 file changed +8
-1
lines changed
1 file changed +8
-1
lines changed Original file line number Diff line number Diff line change @@ -61,7 +61,7 @@ def test_tuples():
61
61
# pylint: disable=trailing-comma-tuple
62
62
singleton_tuple = 'hello' , # <-- note trailing comma
63
63
assert len (singleton_tuple ) == 1
64
- assert singleton_tuple == ('hello' , )
64
+ assert singleton_tuple == ('hello' ,)
65
65
66
66
# The following example is called tuple packing:
67
67
packed_tuple = 12345 , 54321 , 'hello!'
@@ -76,3 +76,10 @@ def test_tuples():
76
76
# right-hand side. Sequence unpacking requires that there are as many variables on the left
77
77
# side of the equals sign as there are elements in the sequence. Note that multiple assignment
78
78
# is really just a combination of tuple packing and sequence unpacking.
79
+
80
+ # Swapping using tuples.
81
+ first_number = 123
82
+ second_number = 456
83
+ first_number , second_number = second_number , first_number
84
+ # Data can be swapped from one variable to another in python using
85
+ # tuples. This eliminates the need to use a 'temp' variable.
You can’t perform that action at this time.
0 commit comments