Math operation (7):
- abs: The function returns the absolute value of a number.
- divmod: Calculates the result of the divisor and dividend, returning a tuple (a // b, a % b) containing the quotient and remainder.
- round: Preserves the number of decimal places for floating-point numbers, and integers are reserved by default.
- pow: Find the power of x**y. (The result of the three parameters x**y is the remainder of z)
1 print (abs(-5)) # 5 2 3 print (divmod(7,2)) # (3, 1) 4 5 print (round(7/3,2)) # 2.33 6 print (round(7/ 3)) # 2 7 print (round(3.32567,3)) # 3.326 8 9 print (pow(2,3)) #The two parameters are 2**3 power 10 print (pow(2,3,3) ) #The three parameters are the power of 2**3, and the remainder is 3.
- sum: Perform a sum calculation on an iterable object (initial value can be set).
- min: Returns the minimum value of the iterable object (key can be added, the key is the function name, and the minimum value is returned through the rules of the function).
- max: Returns the maximum value of the iterable object (key can be added, the key is the function name, and the maximum value is returned through the rules of the function).
1 print(sum([1,2,3])) 2 #6 3 print(sum((1,2,3),100)) 4 #106 5 print(sum([1,2,3],100)) 6 #106 7 print(min([1,2,-5,],key=abs)) 8 #1 9 dic = {'a':3,'b':2,'c':1} 10 print(min(dic,key=lambda x:dic[x])) 11 #c 12 print(max([1,2,3],key=abs)) 13 #3 14 print(max([1,2,-6],key=abs)) 15 #-6 16 dic = {'a':3,'b':2,'c':1} 17 print(max(dic,key=lambda x:dic[x])) 18 #a