Skip to content

Python min() function | Basic

  • by

Python min() function returns the lowest value in an iterable object or finds the smallest item between two or more parameters.

Find the smallest item in an iterable object (Lists, Tuples, etc.)

min(iterable) 

Or

Find the smallest item between two or more objects

min(n1, n2, n3, ...) 

Python min() function example

Simple example code use min() functions, If the values are strings, an alphabetical comparison is done.

Using min() with iterable arguments

Let’s get the smallest item on a list.

number = [3, 2, 8, 5, 10, 6]
res = min(number)


print("The smallest number is:", res)

Output:

Python min() function

The smallest string in a list

languages = ["Python", "C++", "Java", "JavaScript"]
res = min(languages);

print("The smallest string is:", res)

Output:

The smallest string is: C++

Do comment if you have any doubts or suggestions on this Python basic topic.

Note: IDE: PyCharm 2021.3.3 (Community Edition)

Windows 10

Python 3.10.1

All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.

Leave a Reply

Your email address will not be published. Required fields are marked *