TUPLE DATATYPE


TUPLE DATATYPE

Tuple in Python is similar to the Lists data type in Python in many ways especially in the syntax part, but Tuple is a read-only data structure as we can’t modify the size and value of the items of the tuple and its enclosed within round() braces. Here the slice, concatenating, and the repetition operator have the same working style as in strings and lists.

In Python, Tuples are practised to store several items in one single variable. And a tuple is one of 4 built-in data types applied to store groups of data; the additional 3 are List, Set, and Dictionary, each with distinct qualities and ways. A tuple can be a collection that is ordered and unchangeable. And they are written along with the round brackets.

The Tuple Items in Python:

Tuple items can be ordered, unchangeable, and enable duplicate values too. They are indexed, the first item has index [0], and the second item has index [1].

Ordered:

If the tuples are ordered, the items have a specified order, and the order will not change.

Unchangeable:

When we say tuples are unchangeable, we cannot change, add or remove items when the tuple has been created.

Enable Duplicates:

As tuples are indexed, they also have items with identical value.

Tuple Length:

To know how many items a tuple has, we use the len() function.

To Create Tuple With One Item:

Create a tuple with one item; we must apply a comma after the item unless Python does not accept it as a tuple.

    The Tuple Items in Python: Tuple items can be ordered, unchangeable, and enable duplicate values too. They are indexed, the first item has index [0], and the second item has index [1].

    Ordered: If the tuples are ordered, the items have a specified order, and the order will not change.

    Unchangeable: When we say tuples are unchangeable, we cannot change, add or remove items when the tuple has been created.

    Enable Duplicates: As tuples are indexed, they also have items with identical value.

    Tuple Length: To know how many items a tuple has, we use the len() function.

    To Create Tuple With One Item:  Create a tuple with one item; we must apply a comma after the item unless Python does not accept it as a tuple.

Example:

x = ("Knowledge2life", "Knowledge2life 1") print(x)

OUTPUT:

('Knowledge2life', 'Knowledge2life 1')