The min and max Functions in Python:-
Python has two built-in functions named min and max that work with sequences. The min function accepts a sequence, such as a list or a string, as an argument and returns the item that has the lowest value in the sequence. Here is an example:
my-list = [5, 4, 3, 2, 50, 40, 30]
print 'The lowest value is', min(my-list)
This code will display the following:
The lowest value is 2
The max function accepts a sequence, such as a list or a string, as an argument and returns the item that has the highest value in the sequence. Here is an example:
my-list = [5, 4, 3, 2, 50, 40, 30]
print 'The highest value is', max(my-list)
This code will display the following:
The highest value is 50


LinkBack URL
About LinkBacks
Reply With Quote

LinkBacks Enabled by vBSEO
Bookmarks