December 2018
Beginner to intermediate
796 pages
19h 54m
English
The last immutable sequence type we're going to see is the tuple. A tuple is a sequence of arbitrary Python objects. In a tuple, items are separated by commas. They are used everywhere in Python, because they allow for patterns that are hard to reproduce in other languages. Sometimes tuples are used implicitly; for example, to set up multiple variables on one line, or to allow a function to return multiple different objects (usually a function returns one object only, in many other languages), and even in the Python console, you can use tuples implicitly to print multiple elements with one single instruction. We'll see examples for all these cases:
>>> t = () # empty tuple>>> type(t)<class 'tuple'>>>> one_element_tuple = (42, ) # you ...
Read now
Unlock full access