Python built-in functions and python built-in functions
# Mathematical functions # import math to the Mathematical Module # floor () Round-down result = math. floor (6.2) print (result) # ceil () rounded up result = math. ceil (5.5) print (result) # round () Rounding Note: not a function in math, the system comes with # n.5. When n is an odd number, if it is an even number, the result = round (8, 5) print (result) # pow () calculates the n result of A number = math. pow (5, 3) print (result) result = 5 ** 3 print (result) # sqrt () Square operation result = math. sqrt (5) print (result) # abs () calculates the absolute value of a value. The built-in function (Original Value Type) result = abs (-12) print (result) # modf () set Split Floating Point numbers into integers and decimals. The result is math. modf (12.5) print (result) # copysign () assigns the positive and negative values of the second number to the first number result = math. copysign (12,-5) print (result) # fsum calculates the sum of numbers in a sequence (floating point number) listvar = [, 6] result = math. fsum (listvar) print (result) # sum () calculates the sum of numbers in a sequence (determined based on the data content) listvar =, 6] result = sum (listvar) print (result) # max () gets the maximum nums in the sequence = [, 67] result = max (nums) print (result) # max () returns the maximum value r of multiple data. Esult = max (23,4, 56,21, 34,62, 8, 16) print (result) # min () obtains the minimum value of result = min (nums) print (result) # min () return the minimum value result = min (23,4, 56,21, 34,62,) print (result) # range () to generate an integer within the specified range (generator). Note: contain start does not contain end result = range () print (result) for I in result: print (I) # values commonly used in the math module # pi circumference rate print (math. pi) # e natural logarithm print (math. e) # random Number Module import random # random dom () random acquisition 0 ~ Decimal number between 1 (including 0 but not 1) result = random. random () print (result) # choice () returns A random value of listvar = [, 9, 'C', 'D', 'A ', 'X'] result = random. choice (listvar) print (result) # shuffle () random disruption list listvar = ['mf ', 'Sl', 'yj', 'lss ', 'cyy'] print (listvar) random. shuffle (listvar) print (listvar) # randrange () gets a random integer in the specified range. result = random. randrange (3, 8, 5) print (result) # uniform () gets the random number in the specified range. result = random. uniform () print (result) # hexadecimal correlation # hex () converts a hexadecimal value to a hexadecimal value var = 15 result = hex (var) print (result, type (result) # oct () converts decimal to octal var = 46 result = oct (var) print (result, type (result) # bin () convert the 10th to 2nd var = 38 result = bin (var) print (result, type (result )) # ascii ''' American standard information interchange code 0-9-> 48-57A-Z-> 65-90a-z-> 97-122 ''' # ord () get the corresponding ascii code result = ord ('A') print (result) # chr () Get the corresponding character result = chr (80) print (result) based on the ascii code) # repr () Output string as is (escape characters without quotation marks) var = 'If life \ 'Cheat \ 'You \ n don't be sad don't worry' print (var) result = repr (var) print (result) # eval () execute python strings as python code. use num = 99var = 'num + 1' num = eval (var) print (num) with caution)