Tuple In Python | How to use tuple in python | Python Tuples
Tuple In Python
A tuple is similar to the list in many ways. Like lists, tuples also contain the collection of the items of different data types. The items of the tuple are separated with a comma (,) and enclosed in parentheses (). A tuple is a read-only data structure as we can't modify the size and value of the items of a tuple.
Example:
Output:
Accessing Tuple
Accessing the tuple is pretty easy, we can access tuple in the same way as List.
Example:
Output:
Adding Tuples
Tuple can be added by using the concatenation operator(+) to join two tuples.
Example:
Output:
Replicating Tuple
Replicating means repeating. It can be performed by using '*' operator by a specific number of times.
Example:
Output:
Tuple Slicing
A subpart of a tuple can be retrieved on the basis of an index. This subpart is known as tuple slice.
Example:
Output:
Tuple Deleting
Deleting individual elements from a tuple is not supported. However, the whole of the tuple can be deleted using the del statement.
Example:
Output:
min(tuple) Method
This method is used to get min value from the sequence of tuple.
Example:
Output:
max(tuple) Method
This method is used to get the max value from the sequence of tuple.
Example:
Output:
len(tuple) Method
This method is used to get the length of the tuple.