What are tuples in Python
Python tuple is a collection or an array which is used to store various types of data.
Features of Python Tuples:
- They are ordered and unchangeable.
- They are written within round brackets.
- They can store multiple types of data.
- They are immutable. Thus, it cannot be modified.
- Python Tuples supports various operations.
- The elements of a python tuple are separated by commas and starts with index 0.
Python Tuples Methods:
|cmp()||To compare two tuples.|
|count()||Returns the number of times a specified value occurs in a tuple.|
|index()||Searches the tuple for a specified value and returns the position of where it was found.|
|min()||To get the minimum value from the tuple.|
|max()||To get the maximum value from the tuple..|
|len()||To get the number of elements in a tuple.|
|tuple()||To convert a sequence type to a tuple.|
Python Tuples Operators:
|Concatenation||+||To add two tuples.|
|Replication||*||To repeat the tuple a specific number of times.|
|Slicing||[i:j]||To get a sub-tuple of specified start and end index.|
|Deleting||del||To delete an element from the tuple.|