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)