Python min() 函数
描述
返回最小值,用法与 max() 相同。
语法
min(iterable, *, key=None, default) / min(a, b, ...)
参数
| 参数 | 说明 |
|---|---|
iterable | 可迭代对象 |
key | 比较依据函数 |
default | 为空时的默认值 |
返回值
最小的元素
实例
prices = {"苹果": 6.5, "香蕉": 3.2, "橙子": 4.8}
print(min(prices.values()))
print(min(prices, key=prices.get))以上实例输出结果为:
3.2
香蕉