1. Abnormality
When an error is detected, the Python interpreter cannot continue execution and instead displays some prompt errors.
Basic syntax:
try:
可能发生的错误
except:
如果出现异常执行的代码
2. Exception transmission
3. Module
import time
print("你好")
time.sleep(5)
print("你好")
from time import *
print("你好")
sleep(5)
print("你好")
#使用from 导入time的sleep功能(函数)
from time import sleep
print("你好")
sleep(5)
print("你好")
asdefine alias
4. Custom modules
Each Python file can be used as a module. The name of the module is the name of the file. That is, the custom module name must comply with the identifier naming rules.
Note: When importing multiple modules, and the modules have the same function, when this function is called, the function of the module imported later is called.
5. Python package
Physically, a package is a folder, which contains a file_init_.py
. This file can be used to contain multiple module files. Logically, The essence of a package is still a module.
6. Third-party packages
Install third-party packages—pip
The installation of third-party packages is very simple, we only need to use Python's built-in pip program.
Open the command prompt and enter
pip install 包名称
You can quickly install third-party packages through the network
Network optimization for pip
Since pip is connected to foreign websites to download packages, sometimes the speed will be very slow.
We can use the following command to connect to domestic websites for package installation:
It is recommended to use (Tsinghua Mirror Source)
pip install - i https://pypi.tuna.tsinghua.edu.cn/simple 包名称
Install third-party packages—PyCharm