Python offers many built-in function and methods for tuple manipulation.
- len()- This returns the length of the tuple that is a total number of elements in the tuple.
syntax:-
len(tuple_name)
e.g.,
l=(2,4,6,8,10,12,14,16) len(l)
Output- 8
- max()- This method returns the element from tuple having maximum value.
syntax:-
max(tuple_name)
e.g.,
t=(8,10,2,12,22,28) max(t)
Output- 28
- min()- This method returns the element from the tuple having minimum value.
syntax:-
min(tuple_name)
e.g.,
t=(8,10,2,12,22,28) min(t)
Output- 2
- tuple()- This method is used to create tuple from different types of values.
syntax:-
tuple(sequence_name)
e.g.,
s="Python" t=tuple(s) print(t)
Output- ('p', 'y', 't', 'h', 'o', 'n')
This is all about functions and methods of tuple in python.