May 2017
Intermediate to advanced
310 pages
8h 5m
English
Tuples are immutable sequences of arbitrary objects. They are indexed by integers greater than zero. Tuples are hashable, which means we can sort lists of them and they can be used as keys to dictionaries. Syntactically, tuples are just a comma-separated sequence of values; however, it is common practice to enclose them in parentheses:
tpl= ('a', 'b', 'c')
It is important to remember to use a trailing comma when creating a tuple with one element, for example:
t = ('a',)
Without the trailing comma, this would be interpreted as a string.
We can also create a tuple using the built-in function tuple(). With no argument, this creates an empty tuple. If the argument to tuple() is a sequence then this creates a tuple of elements of that ...