The min() function in Python is a built-in function used to find the smallest element among a group of values. It can be used with multiple values or with an iterable object such as a list, tuple, set, or string.
The function compares the values and returns the minimum (smallest) value.
It is commonly used in programs where we need to identify the lowest number, smallest item, or earliest value in a dataset.
Syntax 1: Using multiple arguments
min(value1, value2, value3, ...)
Syntax 2: Using an iterable
min(iterable, key=None)
value1, value2, ... Two or more values to compare.
iterable A sequence such as a list, tuple, or set whose smallest element needs to be found.
key (optional) A function used to customize the comparison.
print(min(10, 5, 20, 3))
Output
3
Explanation
numbers = [8, 2, 15, 4, 10]
print(min(numbers))
Output
2
Explanation
numbers = (12, 7, 25, 5)
print(min(numbers))
Output
5
Explanation
text = "python"
print(min(text))
Output
h
Explanation
'h' is the smallest.key Parameterwords = ["apple", "banana", "kiwi", "cherry"]
print(min(words, key=len))
Output
kiwi
Explanation
key=len argument tells Python to compare words based on their length."kiwi" has the smallest length.marks = [85, 90, 78, 88]
lowest = min(marks)
print("Lowest Marks:", lowest)
Output
Lowest Marks: 78
Explanation
min() is a built-in Python function used to find the smallest value.key parameter for custom comparison.