Python Tutorial Python Advanced Python References Python Libraries

Python min() Function



The Python min() function returns smallest element in an iterable. An iterable object can be any data structure like list, tuple, set, string, dictionary and range iterable.

Syntax

#to compare one or more elements
min(n1, n2, n3, .....)

#to compare all elements of an iterable
min(iterable)

Parameters

iterable Required. iterable object like list, tuple, set, string , dictionary and range() etc.

Example: min() function applied on numerical iterable

In the example below, min() function is used to find out the smallest element in a given iterable.

MyList = [10, 5, 15, 20, 25, 30]
print(min(MyList))

MyRange = range(10, -5, -1)
print(min(MyRange))

x = min(10, 0, 14, 18, 20, 30)
print(x)

The output of the above code will be:

5
-4
0

Example: min() function applied on a string iterable

When min() function is applied on a string iterable, it returns smallest value, ordered alphabetically.

MyList = ['Marry', 'Sam', 'John', 'Joe']
print(min(MyList))

The output of the above code will be:

Joe

❮ Python Built-in Functions

5