Python built-in functions max (), min (), pythonmin
max
(Iterable,*[,Key,Default])
max
(Arg1,Arg2,* Args[,Key])
The function is used to obtain the maximum values of multiple input parameters or the maximum values of the input iteratable object elements. The default value is Numeric. The value is greater than the default value. The value is sorted by the alphabetic order by the latter. You can also pass in the named parameter key as a function to specify the method to take the maximum value. The default naming parameter is used to specify the default value returned when the maximum value does not exist.
Eg
A. Maximum Value of multiple input parameters
print(max(1,2,3,4))
Output
4
B .1 when an iteratable object is passed in, the maximum value of its element is obtained.
s = '12345'print(max(s))
Output
5
B .2 when an iteratable object is null, you must specify the default parameter to return the default value.
print(max((),default=1))print(max(()))
Output
1 Traceback (most recent call last): File "G:/pycode/built-in functions/max_ex.py", line 8, in <module> print (max () ValueError: max () arg is an empty sequence
C. input the named parameter key as a function to specify the method for obtaining the maximum value.
s = [ {'name': 'sumcet', 'age': 18}, {'name': 'bbu', 'age': 11}]a = max(s, key=lambda x: x['age'])print(a)
Output
{'name': 'sumcet', 'age': 18}
Min () function and max () function use the same, return the minimum value