Python max() Function
Definition and Usage
The max() function returns the item with the maximum value, or the item with the maximum value in the iterable.
If the value is a string, it is compared in alphabetical order.
Syntax
max(n1, n2, n3, ...)
Or:
max(iterable)
Parameter Value
Parameter | Description |
---|---|
n1, n2, n3, ... | One or more items to be compared. |
Or
Parameter | Description |
---|---|
iterable | An iterable object containing one or more items for comparison. |
More Examples
Example
Return the name with the highest value, sorted alphabetically:
x = max("Steve", "Bill", "Elon")
Example
Return the item with the highest value in the tuple:
a = (1, 5, 3, 9, 7) x = max(a)
Related Pages
Reference Manual:min() Function(Return the Lowest Value)