Tuple functions
If you want to know the length of the tuple, then you can use the len()
function.
len()
The syntax for the method is as follows:
len(tuple)
The len()
function returns the length of the tuple, which means the total number of elements in a tuple.
>>> tup1 = ("C", "Python", "java","html") >>> len(tup1) 4 >>>
Let's see how to use the max()
function on a tuple.
max()
The syntax for the method is as follows:
max(tuple)
The max(tuple)
function returns the element of tuple with the maximum value.
You must be in doubt with the meaning of maximum value.
Let's understand with examples:
>>> t2 = (1,2,3,4,510) >>> max(t2) 510
The max
function returns the maximum integer value.
If the tuple contains int and float with the same numeric value, which value would be returned can you guess? Let’s see with this example:
>>> t2 = (1,2,450.0,450) >>> max(t2) 450.0 >>>
If you are thinking it returns a float value, see the next example:
>...