A tuple is a sequence of immutable Python objects. Tuples are sequences, just like lists. The differences between tuples and lists are, the tuples cannot be changed unlike lists and tuples use parentheses, whereas lists use square brackets.
Python includes the following tuple functions −
Sr.No. | Function & Description |
---|---|
1 | cmp(tuple1, tuple2)
Compares elements of both tuples. |
2 | len(tuple)
Gives the total length of the tuple. |
3 | max(tuple)
Returns item from the tuple with max value. |
4 | min(tuple)
Returns item from the tuple with min value. |
5 | tuple(seq)
Converts a list into tuple. |
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 |