Home > Article > Backend Development > Python - Learn Note (3)
Package is a folder; a package can have multiple levels;
Module is the xxx.py file; you can create your own modules and import them. The name of the module is the same as the name of the file;
Python uses the import statement to import a module.
import math
print math.sqrt(16) # => 4
Only want to import certain functions of the used math module
from math import ceil, floor
print ceil(3.7) # => 4.0
print floor(3.7) # => 3.0
# Import all definitions from the module
# Warning: Deprecated
from math import *
Using from...import to import functions sometimes causes conflicts with the same name. At this time, you can give the function an "alias" to avoid conflicts ;
from math import log from logging import log as logger <span style="color: #b22222"># logging的log现在变成了logger print log(10) <span style="color: #b22222"># 调用的是math的log logger(10, 'import from logging') <span style="color: #b22222"># 调用的是logging的log</span></span></span>
# You can also use the dir method to check what attributes and methods are in the module
import math
dir(math)
The above is the detailed content of Python - Learn Note (3). For more information, please follow other related articles on the PHP Chinese website!