Python max()
is a built-in function that returns the maximum value among the arguments supplied to the function. If an iterable is passed as the argument, the largest item in the iterable is returned.
max (num1, num2, *args[, key])
Where,
There can be any number of objects supplied as arguments for comparison.
max(iterable, *[, key, default])
Where,
ValueError
will be raised.When an iterable is passed as the argument, the largest item of the iterable is returned. If multiple iterables are passed then, the list for which the key function return greater value is returned.
>>> max(1,2,3,4)
4
>>> py_num = [3,5,7,9]
>>> max(py_num)
9
def findMax(num):
rem = 0
while(num):
rem = num%10
return rem
# using max(arg1, arg2, *args, key)
print('Number with max remainder is:', max(11,48,33,17,19, key=findMax))
# using max(iterable, key)
num = [11,48,33,17]
print('Number with max remainder is:', max(num, key=findMax))
When executed, this will yield following output.
Number with max remainder is: 19 Number with max remainder is: 48