Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/data_types/test_tuples.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def test_tuples():
# pylint: disable=trailing-comma-tuple
singleton_tuple = 'hello', # <-- note trailing comma
assert len(singleton_tuple) == 1
assert singleton_tuple == ('hello', )
assert singleton_tuple == ('hello',)

# The following example is called tuple packing:
packed_tuple = 12345, 54321, 'hello!'
Expand All @@ -76,3 +76,10 @@ def test_tuples():
# right-hand side. Sequence unpacking requires that there are as many variables on the left
# side of the equals sign as there are elements in the sequence. Note that multiple assignment
# is really just a combination of tuple packing and sequence unpacking.

# Swapping using tuples.
first_number = 123
second_number = 456
first_number, second_number = second_number, first_number
# Data can be swapped from one variable to another in python using
# tuples. This eliminates the need to use a 'temp' variable.