Python min Function with Examples - Python Tutorial | Logic Practice
Python Course / Other / Python min Function with Examples

Python min Function with Examples

BLUF: This lesson on Python min Function with Examples provides a comprehensive guide to understanding and implementing this concept in Python. Whether you're a beginner or looking to refresh your knowledge, you'll find clear explanations and interactive code examples here.
Key Concept: Python min Function with Examples

Mastering Python min Function with Examples is essential for building efficient Python applications. Focus on the syntax and the best practices highlighted in this tutorial.

The min function in Python is utilized to retrieve the smallest item from a given collection. This function requires two parameters: the first is a collection of items, while the second is an optional key. It returns the minimum element found within the provided collection.

Python min Function Syntax

It has the following syntax:

Example

min (collection[, key])

Parameters

  • collection : It is a comma-separated list of elements.
  • key : Specifies a one-argument ordering function.
  • Return

It retrieves the least value from the set of elements.

Different Examples for Python Min Function

Let’s explore various instances of the min function to gain a clearer comprehension of its capabilities.

Python min Function Example 1

Here is a straightforward illustration of how to retrieve the smallest element from a collection. Refer to the example provided below.

Example

# Python min() function example

# Calling function

small = min(2225,325,2025) # returns smallest element

small2 = min(1000.25,2025.35,5625.36,10052.50)

# Displaying result

print(small)

print(small2)

Output:

Output

325

1000.25

Python min Function Example 2

Let us consider an example to illustrate the functionality of the Python min function.

Example

# Python min() function example

# Calling function

small = min('a','A','b','B') # returns smallest element

small2 = min([10,12],[12,21],[13,15])

# Displaying result

print(small)

print(small2)

Output:

Output

A

[10, 12]

Python min Function Example 3

Let us consider an additional example to illustrate the functionality of the Python min function.

Example

# Python min() function example

# Calling function

small = min("Python","Python","Scala") # returns smallest element

small2 = min([10,12,33],[12,21,55],[13,15], key=len) # returns smallest element's length

# Displaying result

print(small)

print(small2)

Output:

Output

Java

[13, 15]

Input Required

This code uses input(). Please provide values below:

Logic Practice
Install Logic Practice
Add to home screen for a faster app-like experience