February 2006
Intermediate to advanced
648 pages
14h 53m
English
Closely related to lists is the tuple data type. You create tuples by enclosing a group of values in parentheses, like this:
a = (1,4,5,-9,10) b = (7,) # Singleton (note extra ,) person = (first_name, last_name, phone)
Sometimes Python recognizes that a tuple is intended, even if the parentheses are missing:
a = 1,4,5,-9,10 b = 7, person = first_name, last_name, phone
Tuples support most of the same operations as lists, such as indexing, slicing, and concatenation. The only difference is that you cannot modify the contents of a tuple after creation (that is, you cannot modify individual elements or append new elements to a tuple).
Read now
Unlock full access