Useful Methods / Functions
There are two methods that can be used for the
tuple data type, namely
count() and
index().
The
count(data) method returns the number of occurrences of the object sent as a parameter within the tuple.
The
index(object) method returns the first position (index) of the object within the tuple.
Note: If the value is not found, the methods return an interpretation error and not a specific value!
Therefore, be careful when creating programs as execution will stop when such an error occurs.
You can also use a series of other built-in functions, such as:
min(),
max(),
len(),
reversed(),
sum(), etc.
Moreover, the
sorted() function
returns a list with the elements of a tuple in
ascending or
descending order.
Example: sorted(tuple) or
sorted(tuple, reverse=True).
Proceed to the next page.