Student Handbook

Student Handbook

Open in ChatGPT
Ask ChatGPT about this page
Open in Claude
Ask Claude about this page

max

Returns the largest of several values.

Synopsis

max(value1, value2, ...)
max(list)

Description

Give max two or more values, or one list.

Parameters

Name Meaning
values Two or more values, or one list. They must be comparable: all numbers, or all strings.

Return value

The largest value.

Example

print(max(3, 7, 1))
print(max(["apple", "pear", "fig"]))

It prints:

7
pear

Common mistake

scores = []
print(max(scores))

Python stops with:

ValueError: max() iterable argument is empty

An empty list has no largest item. Check if scores: first.

See also

min, sum, len

max in the Python documentation

Last updated 2 weeks ago