This article will explain how to find the maximum and minimum values from a tuple in python using max() and min() functions.

Python max() function
max() function accepts an iterable as argument and returns the highest value in the iterable. An iterable is a sequence that can be iterated or loop over such as a list, tuple or a string.

If the tuple is of numbers, then it returns the number with highest value. If the tuple is of strings, then it returns the string whose characters appear last in the alphabetic order.
Example,

numbers = (1, 2, 3, 4, 5)
print('Largest number is:',max(numbers))

strings = ('axe', 'zebra', 'orange', 'brown')
print('Highest string is:',max(strings))

This prints

Largest number is: 5
Highest string is: zebra

Python min() function
Similar to max(), min() function also accepts an iterable and returns the item with minimum value in the iterable.
For a sequence of numbers, the returned value is the minimum number while for sequence of strings, the returned value is a string that appears first in alphabetic order.
Example,

numbers = (1, 2, 3, 4, 5)
print('Largest number is:',min(numbers))

strings = ('axe', 'zebra', 'orange', 'brown')
print('Highest string is:',min(strings))

Output is
Largest number is: 1
Highest string is: axe
Hope the article was useful.
Also check: Find maximum item in a list in python

1
Close Menu

Never Miss an article !

Get the new post delivered straight into your inbox, enter your email and hit the button

You have successfully subscribed to the newsletter

There was an error while trying to send your request. Please try again.

codippa will use the information you provide on this form to be in touch with you and to provide updates and marketing.