tuples
Tuple Data Type
Tuple is a built-in immutable data type that is used to store a collection of data. It can be of the same or different data type. It’s best suitable for storing a data that cannot change since it’s immutable, unlike a list whose elements can be modified.
Creating a tuple
A tuple data type can be created using a comma separated-values placed within a parenthesis ().
Example:
Note
When creating a tuple with one item, we put a comma after that item.
Other ways of creating a tuple
There are other ways of creating a tuple which we’ll mention.
using tuple()
constructor
One of the built-in tuple()
function is also used to create a tuple. It takes a sequence data type and constructs a tuple with it’s items. If no argument is provided then it will construct an empty tuple.