python max函数_Python3

max(x, y[, z...]):Number|Sequence 入参类型不能混入(要么全Number(int|float|complex|bool),要么全序列)。

入参是序列的话: 单序列入参,返回序列中最大的一个数值多序列入参, 按索引顺序,逐一对比各序列的当前索引位的 “值”,直到遇见最大值立即停止对比,并返回最大值所在的序列(也就是说,多序列入参,返回值依旧是一个序列,而不是数值)

>>> import sys; sys.version

'3.8.2 (tags/v3.8.2:7b3ab59, Feb 25 2020, 23:03:10) [MSC v.1916 64 bit (AMD64)]'

>>> max(0, True) #布尔喔

True

>>> max([1,2,3])

3

>>> max(1,2,4)

4

>>> max(-1, -0.5, 0)

0

>>> max((1,2,3))

3

>>> max([2,4], [3,6])

[3, 6]

>>> max([2,4], [1,5])

[2, 4]

>>> max([2,4], [1,5], [3,1], [2,5],[0,7])

[3, 1]

>>> max((1,2,3), (3,3,0))

(3, 3, 0)

>>> max((1,-1,0), (True,False,0)) #布尔喔

(True, False, 0)

>>> max((1,-1,0), (True,False,2,0),(1, 0, 0, 2))

(True, False, 2, 0)

>>> max((1,-1,0), (True,),(1,))

(1, -1, 0)

>>> max((-1,-1,0), (True,),(1,))

(True,)

>>> max([1,3,2],3,4) #非法入参

Traceback (most recent call last):

File "", line 1, in

TypeError: '>' not supported between instances of 'int' and 'list'

>>> max((1,2,3), [2,4,1]) #非法入参

Traceback (most recent call last):

File "", line 1, in

TypeError: '>' not supported between instances of 'list' and 'tuple'

vipkwd

vipkwd

ser***e@vipkwd.com3个月前 (09-04)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值