Python- Tuples
A tuple is the collection which is ordered and unchangeable. In Python tuples are written with round brackets.
Example
Create a Tuple:
thistuple = ("apple", "orange", "cherry")
print(thistuple)
Output:
C:\Users\My Name>python demo_tuple.py
('apple', 'orange', 'cherry')
There are the following Tuple Method:
Method |
Description |
Python Tuple count() |
returns occurrences of element in a tuple |
Python Tuple index() |
returns smallest index of element in tuple |
Python any() |
Checks if any Element of an Iterable is True |
Python all() |
returns true when all elements in iterable is true |
Python ascii() |
Returns String Containing Printable Representation |
Python bool() |
Converts a Value to Boolean |
Python enumerate() |
Returns an Enumerate Object |
Python filter() |
constructs iterator from elements which are true |
Python iter() |
returns iterator for an object |
Python len() |
Returns Length of an Object |
Python max() |
returns largest element |
Python min() |
returns smallest element |
Python map() |
Applies Function and Returns a List |
Python reversed() |
returns reversed iterator of a sequence |
Python slice() |
creates a slice object specified by range() |
Python sorted() |
returns sorted list from a given iterable |
Python sum() |
Add items of an Iterable |
Python tuple() Function |
Creates a Tuple |
Python zip() |
Returns an Iterator of Tuples |