Python: Tuple

Tuple is a heterogeneous data structure which represented immutable sequence of objects.
It means that once tuple is created, the objects within it cannot be replaced or deleted, as well as new elements cannot be added.

Why tuple is useful

  • tuple is used in case of returning multiple resuts from a function
  • tuple can be used as key for a dictionary because it is immutable

Basic operations

Nested tuples

Tuple with one element

NOT A tuple:

IT IS tuple:
Don`t forget to include a trailing comma to create a single tuple.

How to return multiple values

IN and NOT IN in tuples

Get tuples from iterable structures

You may also like