max(number_one, number_two)
max(value,run)
should do it.
(num1>=num2)*num1+(num2>num1)*num2
will return the maximum of two values.
numberList=[16,19,42,43,74,66]
largest = numberList[0]
for num2 in numberList:
if num2 > largest:
largest=num2
print(largest)
gives largest number out of the numberslist without using a Max statement
I noticed that if you have divisions it rounds off to integer, it would be better to use:
c=float(max(a1,...,an))/b
Sorry for the late post!
You can use max(value, run)
The function max
takes any number of arguments, or (alternatively) an iterable, and returns the maximum value.
You could also achieve the same result by using a Conditional Expression:
maxnum = run if run > value else value
a bit more flexible than max
but admittedly longer to type.
Just for the fun of it, after the party has finished and the horse bolted.
The answer is: max()
!
Source: Stackoverflow.com