Python max() Function

Example

Return the largest number:

x = max(5, 10)

Run Instance

Definition and Usage

The max() function returns the item with the largest value, or the item with the largest 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 compare.

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")

Run Instance

Example

Return the item with the highest value in the tuple:

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

Run Instance

Related Pages

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