模块 Modules
dog.py
def bark():
print("woof!")
main.py
import dog
from dog import bark
dog.bark() # "woof!"
bark() # "woof!"
Create lib
folder
__init__.py (nothing here, just to delcare the lib is a module in python)
dog.py
def bark():
print("woof!")
main.py
from lib import dog
from lib.dog import bark
dog.bark() # "woof!"
bark() # "woof!"
Buit-in modules
math
for math utilitiesre
for regular expressionsjson
to work with JSON datetime to work with dates sqlite to use SQLiteos
for Operating System utilitiesrandom
for random number generationstatistics
for statistics utilities requests to perform HTTP network requestshttp
to create HTTP serversurllib
to manage URLS
import math
from math import sqrt
math.sqrt(4) # 2.0
sqrt(4) # 2.0