1. Python Built in functions will be assembled into <builtin> Built in module , have access to list(__builtin__.__dict__) perhaps dir(__builtin__) To list all built-in functions , as follows :
Starting today , Learn to use these basic built-in functions , And make records , Enhance learning outcomes .
2. Start with mathematical functions
Python The built-in mathematical functions in realize the basic mathematical operations , Through these functions, data results can be obtained easily and quickly , If you want to implement more complex operations, you can use import Python Third party modules .
Let's introduce the first function of the mathematical function abs() function
abs() function : Get absolute value , Use this function to return the absolute value of a given value , Such as abs(x), return x The absolute value of
give an example 1: Get the absolute value of the number in the list
x_list = [2.8, 3, 0.5, -12, -3.5]
for num in x_list:
print(abs(num))
Running results :
2.8
3
0.5
12
3.5
give an example 2: Define functions to output 2 The absolute value of multiplying numbers
def calcAbs(value1, value2):
return abs(value1 * value2)
Call the defined function and pass parameters , as follows :
print(calcAbs(2.5, 4.3)) # Output results :10.75
print(calcAbs(2.5, -4.3)) # Output results :10.75
abs Function is the most basic function in mathematical function , It's easy to use , You can use this function directly when you need to find the absolute value .