O'Reilly logo

Python: Essential Reference, Third Edition by David Beazley

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Tuples

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).

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required