Module and package

The import module

# import math module, Import math print(id(math)) print(type(math)) # <class 'module'> print(math) # <module 'math' (built-in)> print(math.pi) print(dir(math)) print(math.pow(2, From math import PI print(PI) import calc num = calc.add(10) Import calc2 print(calc2.add(10, 10))Copy the code

The difference between packages and directories

"" package: the folder containing the __init__.py file, called the package directory: Import pack1.fun_a as funa import pack1.fun_b as funb print(funa.a) print(funb.b)Copy the code

Common built-in modules

Import sys import time import urllib.request # sys module; Print (sys.getsizeof(10)) print(sys.getsizeof(20)) print(sys.getsizeof(True)) Print (sys.getsizeof(False)) # time; Print (time.time()) print(time.localtime(time.time())) Standard library of operating system service functions # Calendar module; Standard library for date-dependent functions # urllib module; Print (urllib.request.urlopen("http://www.baidu.com").read()) Serialization and deserialization of Json standard library # re module; The # math module of the standard library for string execution of regular expressions; Standard library for arithmetic operation functions # decimal module; Standard library # logging module for precise computing precision effective bit-correlation functions; Standard library for logging related functionsCopy the code