More Python min() Examples

In this example, we find the minimum element in different reference using Python min().

Example 1: Find Python Min of List

In this example, we are using min() to locate the smallest item in Python in a list.

Python




numbers = [3, 2, 8, 5, 10, 6]
small = min(numbers);
 
print("The smallest number is:", small)


Output

The smallest number is: 2



Example 2: Find min in List of String

In this example, we are using min() to locate the smallest string in Python in a list.

Python




languages = ["Python", "C Programming", "Java", "JavaScript",'PHP','Kotlin']
small = min(languages)
print("The smallest string is:", small)


Output

The smallest string is: C Programming

Example 3: Minimum Element in a Dictionary

In this example, we are using min() to find the minimum element in a dictionary.

Python




square = {5: 25, 8: 64, 2: 4, 3: 9, -1: 1, -2: 4}
 
print("The smallest key:", min(square))    # -2
 
key2 = min(square, key = lambda k: square[k])
 
print("The smallest value:", square[key2])    # 1


Output

The smallest key: -2
The smallest value: 1



In this article, we discussed the definition, syntax, and examples of the Python min() function. min() function in Python is very versatile and can be used with any iterable.

Hope this article helped you understand how to use the min() function, and you can effectively use it in your projects.

Similar Reads:



Python min() Function

Python min() function returns the smallest of the values or the smallest item in an iterable passed as its parameter.

Example: Find Python min integer from the list

Python




numbers = [23,25,65,21,98]
print(min(numbers))


Output

21

Similar Reads

Python min() Function Syntax

...

What is min() Function in Python?

min(a, b, c, …, key=func)...

How to use min() function in Python?

Python min() function is used to find the minimum value. It is the opposite function of max()....

More Python min() Examples

Using min() function in Python is very easy. You just need to pass the list as a parameter in the min function and it will return the minimum number....