一.python max函式簡介
max函式回傳給定引數的最大值,引數可以為序列語法:
max( x, y, z, .... )
回傳值:回傳引數中的最大值;
二.python max函式使用
# !usr/bin/env python # -*- coding:utf-8 _*- """ @Author:何以解憂 @Blog(個人博客地址): shuopython.com @WeChat Official Account(微信公眾號):猿說python @Github:www.github.com @File:python_max.py @Time:2020/03/15 23:35 @Motto:不積跬步無以至千里,不積小流無以成江海,程式人生的精彩需要堅持不懈地積累! """ # max 支持兩個或者多個引數,并回傳最大值 print(max(1,5)) print(max(5.5,6100,1,-10,20))
輸出結果:
5 6100
注意:max函式中的型別只能是int 或者 float型別,其他型別會報錯,例如:
print(max(1,'a')) TypeError: '>' not supported between instances of 'str' and 'int'
猜你喜歡:
1.python區域變數和全域變數
2.python可變型別和不可變型別
3.python深拷貝和淺拷貝
轉載請注明:猿說Python ? python max函式
技術交流、商務合作請直接聯系博主 掃碼或搜索:猿說python
猿說python
微信公眾號 掃一掃關注
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/170787.html
標籤:Python
上一篇:爬蟲之資料決議
下一篇:python 內建函式 zip
