Python Reference Library →

Python min() Function – Find the Smallest Value

Let’s look at min() function – find the smallest value

  1. Notice

    min() returns the smallest item according to comparison or a supplied key.

  2. Try

    Follow the example, change its sample, and compare what happens.

  3. Check

    Explain the result and test your understanding.

Watch how it works

Focus on how the names, objects, and calculations change. We’ll inspect the printed output in the next section.

Explore the idea

Follow the code and watch its state change. Guided simulation.

Code
Python
numbers = [3, 2, 5]
print(min(numbers))
Live state

Top-level scope

numbers→Object 1
Object 1 · list[3, 2, 5]
This step

min() returns the smallest item according to comparison or a supplied key.

Picture min() function – find the smallest value

min() returns the smallest item according to comparison or a supplied key.

Image brief

Alt text
A diagram for Python min() Function – Find the Smallest Value. Instructions: numbers = [3, 2, 5] print(min(numbers)). Displayed result: 2. The final example bindings are numbers --> object 1 (list). object 1: [3, 2, 5]
Image generation prompt
Create a clean educational illustration for a Python programming lesson titled "Python min() Function – Find the Smallest Value". Teaching focus: min() returns the smallest item according to comparison or a supplied key. Depict exactly the relationships and labels in this reference diagram: EXAMPLE INSTRUCTIONS numbers = [3, 2, 5] print(min(numbers)) | v DISPLAYED RESULT 2 FINAL BINDINGS numbers --> object 1 (list) object 1: [3, 2, 5] Use a flat vector style, generous spacing, clear arrows and legible labels, with a restrained blue/teal palette on a plain background. The diagram must explain the programming idea accurately. Do not depict variables as boxes containing copied objects when they share a reference. Avoid mascots, decorative screenshots, logos, gradients and extra text. Landscape composition, approximately 3:2, suitable for a course card. Accessible description: A diagram for Python min() Function – Find the Smallest Value. Instructions: numbers = [3, 2, 5] print(min(numbers)). Displayed result: 2. The final example bindings are numbers --> object 1 (list). object 1: [3, 2, 5]

Follow the execution

Choose a different sample input, then follow every step through to the output. Before revealing it, predict what the program will display.

Execution workspace

Choose a sample and follow its execution. Guided simulation.

Code
Python
numbers = [3, 2, 5]
print(min(numbers))
Live state

Top-level scope

numbers→Object 1
Object 1 · list[3, 2, 5]
This step

The example has finished. Compare the final output with the values and references above.

Terminal
Output
2

What do you expect this program to print?

What does this example display?

numbers = [3, 2, 5]
print(min(numbers))
What does this example display?
Choose one answer. You can try again.

Answer and explanation

2

Follow the printed values in order. The output is: 2

More examples and reference

Python min() Function

The min() function in Python returns the smallest item from a list, tuple, or multiple values passed to it. It is one of the most useful built-in functions for comparing and analyzing data.

Syntax

min(iterable, *[, key, default])
min(arg1, arg2, *args[, key])

Parameters:

  • iterable: A sequence (like list, tuple, set, etc.) of comparable items.
  • arg1, arg2, *args: Two or more values for direct comparison.
  • key (optional): A function to customize the comparison logic.
  • default (optional): Value to return if the iterable is empty (used only with default keyword).

Returns:

  • The smallest item based on natural or key-based ordering.

Example 1: Smallest in a List

numbers = [10, 5, 22, 3, 19]
print(min(numbers))
3

Example 2: Comparing Multiple Values

print(min(4, 1, 7, -2, 9))
-2

Example 3: Smallest String in List

words = ["banana", "apple", "cherry"]
print(min(words))
apple

Note: Strings are compared lexicographically (alphabetical order).

Example 4: Using key Parameter

Find the shortest word based on length:

words = ["elephant", "cat", "hippopotamus"]
shortest = min(words, key=len)
print(shortest)
cat

Example 5: Using default with Empty Iterable

empty = []
result = min(empty, default=0)
print(result)
0

Common Mistakes

  • Calling min([]) without a default will raise a ValueError.
  • Comparing incompatible types like strings and numbers will raise a TypeError.

Use Cases

  • Find the minimum score, price, or measurement
  • Identify the earliest date or lowest temperature
  • Sort and filter data by smallest criteria

Interview Tip

min() is frequently used in problems involving optimization, such as finding the minimum distance, cost, or value in arrays.

Summary

  • min() returns the smallest item from a sequence or arguments
  • Supports key for custom comparison
  • Use default to avoid errors with empty iterables

Practice Problem

Write a program that reads five numbers from the user and prints the smallest one.

nums = [int(input("Enter a number: ")) for _ in range(5)]
print("Smallest number is:", min(nums))

What to remember

Connect what you noticed in the example with the idea below.

Remember

min() returns the smallest item according to comparison or a supplied key.

Watch out for this idea

min() always returns the first item of the iterable.

This is the misconception to avoid.

Reference checks are optional and do not count toward course progress.

    Reference library →