MAX


max( a, b )
max "maximum"
a a number
b a number

The max( a, b ) function is used to compare two numbers a and b, and it returns the greater of the two numbers.



For example, if we call max(5, 8), the function will compare the two arguments and determine that 8 is the greater value. Therefore, it will return 8.

greater = max(5,8)
print(greater)  --prints 8

Similarly, if we call max(-3, 0), the function will return 0 since 0 is greater than -3.

greater = max(0,-3)
print(greater)  --prints 0

Images in this Guide by NerdyTeachers is licensed under CC BY-SA 4.0

473

11 Apr 2023

Font