Python max() Function

Example

Return the largest number:

x = max(5, 10)

Run Example

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, containing one or more items to be compared.

More Examples

Example

Return the name with the highest value, sorted alphabetically:

x = max("Steve", "Bill", "Elon")

Run Example

Example

Return the item with the highest value in the tuple:

a = (1, 5, 3, 9, 7)
x = max(a)

Run Example

Related Pages

Reference Manual:min() Function(Return the Minimum Value)