- #1
xDk
- 8
- 0
Hey guys, so I am going through "Learning Python" book and I came across this minmax function.
I don't understand the if statement "if test(arg, res)" I haven't seen an if statement like that before. So that is the first issue. When I run the first function separately, it spits backs what ever I type in as the second argument. When I run either of the second functions it is a true or false. So how do combining the two functions give the min or max values of the numbers. Any help is much appreciated.
Python:
def minmax(test, *args):
res = args[0]
for arg in args[1:]:
if test(arg, res):
res = arg
return res
def lessthan(x, y): return x < y
def grtrthan(x, y): return x > y
print(minmax(lessthan, 4, 2, 1, 5, 6, 3))
print(minmax(grtrthan, 4, 2, 1, 5, 6, 3))
Last edited: