Professional Documents
Culture Documents
06 Tuples
06 Tuples
1 Tuples
A tuple is created by placing all the items (elements) inside parentheses () separated by commas.
It can have any number of items and they may be of different types (integer, float, string etc.)
# empty tuple
my_tuple = ()
# tuple of integers
my_tuple = (5, 9, 3)
# tuple with mixed data types
my_tuple = (1, "Hi!", 3.4j)
Create an empty tuple language then assign to it (“Swahili”, “Arabic”, “English”,
“Swazi”,“French”, “Egede”)
In [2]: t = ("Swahili", "Arabic", "English", "Swazi","French", "Egede")
Tuples are similar to lists except you cannot change elements of a tuple once it is defined.
Whereas in a list, items can be modified. We will then say that a list is mutable whereas a tuple is
immutable
1
1.3 More operations
dir(tuple) or dir(t) where t is a tuple!