def findMinAndMax(L): if not L : return (None, None) min = max = L[0] for n in L: if not isinstance(n, (int, float)): raise TypeError('不支持除了数字外的列表') else: if n > max: max = n if n < min: min = n return (min, max)
>>>print(findMinAndMax([7, 1, 'a', 9, 0.05])) TypeError: 不支持除了数字外的列表 >>>print(findMinAndMax([])) (None, None) >>>print(findMinAndMax([55, 1, 155, 10, 0.05])) (0.05, 155)
>>>
None, False, 空字符串"", 0, 空列表[], 空字典{}, 空元组()都相当于False
Sign in to make a reply
用户6757938931
None, False, 空字符串"", 0, 空列表[], 空字典{}, 空元组()都相当于False