当前位置: 首页 > 图灵资讯 > 行业资讯> Python max() 函数怎么用?什么原理?

Python max() 函数怎么用?什么原理?

发布时间:2024-12-15 20:26:30

max函数经常一起出现的是min函数,对于这两个函数,因为长得差不多,使得经常呗搞混,要如何弄清这两个函数呢?一起来看下把~

示例演示:

Python max() function

max() 该功能用于–

计算在其参数中传递的值。

如果字符串作为参数传递,则在字典上的值。

Find largest integer in array

>>>nums=[1,8,2,23,7,-4,18,23,42,37,2]
>>>max(nums)
42#Maxvalueinarray

Find largest string in array

>>>blogName=["how","to","do","in","java"]
>>>max(blogName)
'to'#Largestvalueinarray

Find max key or value

有点复杂的结构。

>>>prices={
'how':45.23,
'to':612.78,
'do':205.55,
'in':37.20,
'java':10.75
}

>>>max(prices.values())
612.78

>>>max(prices.keys())#ormax(prices).Defaultiskeys().
'to'

好了,以上就是关于max函数的使用了,如需了解更多python实用知识,点击进入PyThon学习网教学中心

相关文章

如何让vim支持python3

如何让vim支持python3

2025-09-12
python2.7和3.6区别有哪些

python2.7和3.6区别有哪些

2025-09-12
python3有serial库吗

python3有serial库吗

2025-09-12
python中w、r表示什么意思

python中w、r表示什么意思

2025-09-12
python中如何把list变成字符串

python中如何把list变成字符串

2025-09-12
python命名空间是什么

python命名空间是什么

2025-09-12