THE WORLD'S LARGEST WEB DEVELOPER SITE

Python max() Function

❮ Built-in Functions


Example

Return the largest number:

x = max(5, 10)
Run example »

Definition and Usage

The max() function returns the item with the highest value, or the item with the highest value in an iterable.

If the values are strings, an alphabetically comparison is done.


Syntax

max(n1, n2, n3, ...)
Or:
max(iterable)

Parameter Values

Parameter Description
n1, n2, n3, ... One or more items to compare
Or:
Parameter Description
iterable An iterable, with one or more items to compare

More Examples

Example

Return the name with the highest value, ordered alphabetically:

x = max("Mike", "John", "Vicky")
Run example »

Example

Return the item in a tuple with the highest value:

a = (1, 5, 3, 9)
x = max(a)
Run example »

Related Pages

The min() function, to return the lowest value.


❮ Built-in Functions