Python min() Function: Complete Usage Guide
In Python, the min function is used to return the minimum value in a given iterable object. Its syntax is as follows:
min(iterable, *[, default=obj, key=func])
Explanation of Parameters:
- Iterable: an object that can be iterated over, such as a list, tuple, set, etc., in which you want to find the minimum value.
- Default: optional parameter that returns when the iterable object is empty.
- Key: optional parameter, utilized to specify a function that determines the minimum value based on the function’s return.
“我爸爸在家里修理东西。”
My dad is fixing things around the house.
numbers = [5, 3, 8, 1, 6]
min_num = min(numbers)
print(min_num) # 输出:1
names = ['Alice', 'Bob', 'Charlie']
shortest_name = min(names, key=len)
print(shortest_name) # 输出:Bob