掃二維碼與項目經(jīng)理溝通
我們在微信上24小時期待你的聲音
解答本文疑問/技術(shù)咨詢/運營咨詢/技術(shù)建議/互聯(lián)網(wǎng)交流
與max函數(shù)經(jīng)常一起出現(xiàn)的是min函數(shù),對于這兩個函數(shù),因為長得差不多,使得經(jīng)常唄搞混,要如何弄清這兩個函數(shù)呢?一起來看下把~

示例演示:
Python max() function
max() 該功能用于–
計算在其參數(shù)中傳遞的值。
如果字符串作為參數(shù)傳遞,則在字典上的值。
Find largest integer in array
>>> nums = [1, 8, 2, 23, 7, -4, 18, 23, 42, 37, 2] >>> max( nums ) 42 #Max value in array
Find largest string in array
>>> blogName = ["how","to","do","in","java"] >>> max( blogName ) 'to' #Largest value in array
Find max key or value
有點復(fù)雜的結(jié)構(gòu)。
>>> prices = {
'how': 45.23,
'to': 612.78,
'do': 205.55,
'in': 37.20,
'java': 10.75
}
>>> max( prices.values() )
612.78
>>> max( prices.keys() ) #or max( prices ). Default is keys().
'to'
好了,以上就是關(guān)于max函數(shù)的使用了,如需了解更多python實用知識,點擊進入PyThon學(xué)習(xí)網(wǎng)教學(xué)中心。

我們在微信上24小時期待你的聲音
解答本文疑問/技術(shù)咨詢/運營咨詢/技術(shù)建議/互聯(lián)網(wǎng)交流