Returns the smallest of several values.
Synopsis
min(value1, value2, ...)
min(list)
Description
Give min 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 smallest value.
Example
print(min(3, 7, 1))
print(min([4.5, 2.5, 9]))
It prints:
1
2.5
Common mistake
print(min("10", "9"))
It prints:
10
Strings are compared letter by letter, and "1" comes before "9", so "10" counts as smaller. Convert numbers you read with input before comparing them.
See also
Last updated 2 weeks ago