Home > Article > Backend Development > How to import math library in python?
The Python language divides functions by distinguishing class libraries. Users load appropriate class libraries according to their own needs to complete the required functions. So how to import and load the class library? The following article will take the built-in class library math as an example to introduce the method of loading the built-in class library. I hope it will be helpful to you.
How to import class libraries in python?
Use the keyword import in python to import and load class libraries. Taking the math library as an example, use the following statement to import the math library:
import math
We can use the alias when importing, which can make the code concise
import math as m
To only import specified functions in the class library, you can use the from...import statement
Python's from statement allows you to import a specified part from the module into the current namespace.
from math import sin as s
If you want to import all the functions of the class library, you can use the from...import* statement
The from...import* statement can import all functions of a module All contents are imported into the current namespace, for example:
from math import *
The above is the detailed content of How to import math library in python?. For more information, please follow other related articles on the PHP Chinese website!