FREE INTERACTIVE ONLINE COURSE

Python 3

FOR BEGINNERS


"The first Python course that simply amazed me. Very well explained and easy to understand." (Alexandru Cosmin)

"The best Python course in Romania." (Iulian Geană)


ALL REVIEWS
LESSON 14
PAGE 3 / 4
Tuples
Home >>> Free Online Lessons, Python 3

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.
Editor - lesson_14.py
       
Console/Output done
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.
 home   list  CONTENTS   perm_identity   arrow_upward