1.导入模块的五种方式
import time
from random import randint
from math import *
import datetime模块 as dt
from copy import deepcopy as dp
2.os模块
import os
print(os.name)
print(os.sep)
print(os.path.abspath('转换.py'))
print(os.path.isdir("转换.py"))
print(os.path.isfile("转换.py"))
print(os.path.exists("转换.py"))
os.getcwd()
os.chdir("test")
os.rename("aa.txt", "bb.text")
os.remove("aaa.txt")
os.rmdir("dd")
os.removedirs("ss")
os.mkdir("aa")
os.chdir("c://")
os.listdir("c://")
os.environ
os.environ.get("PATH")
3.sys模块
import sys
sys.path
sys.exit(100)
sys.argin
sys.stdin
sys.stdout
sys.stderr
4.math模块
import math
math.fabs(-100)
math.ceil(23.21)
math.factorial(5)
math.floor(34.65)
math.pi
math.pow(2, 3)
math.sin(math.pi / 6)
math.coc(math.pi / 6)
math.tan(math.pi / 6)
5.datetime模块
import datetime as dt
print(dt.datetime.now())
print(dt.date(2020, 1, 1))
print(dt.time(18, 23, 56))
print(dt.datetime.now() + dt.timedelta(3))
6.time模块
import time
print(time.time())
print(time.asctime())
print(time.ctime())
print("1")
time.sleep(10)
print("2")
7.calendar模块
import calendar
calendar.setfirstweekday(calendar.SUNDAY)
calendar.firstweekday()
c = calendar.calendar(2019)
print(c)
calendar.isleap(1999)
calendar.leapdays(1995, 2000)
print(calendar.month(2019, 2))
8.hashlib和hmac模块
import hashlib
import hmac
x = hashlib.md5()
x.update("abc".encode("utf8"))
print(x.hexdigest())
h1 = hashlib.sha1("123456".encode())
print(h1.hexdigest())
h2 = hashlib.sha224("123456".encode())
print(h2.hexdigest())
h3 = hashlib.sha3_256("123456".encode())
print(h3.hexdigest())
h4 = hashlib.sha384("123456".encode())
print(h4.hexdigest())
h = hmac.new("h".encode(), "你好".encode())
result = h.hexdigest()
print(result)
9.copy模块
import copy
num = [1, 4, 3, 5, [12, 23, 2], 8]
num1 = copy.copy(num)
num2 = copy.deepcopy(num)
10.uuid模块
import uuid
print(uuid.uuid1())
print(uuid.uuid3(uuid.NAMESPACE_DNS, "zhang"))
uuid.uuid5(uuid.NAMESPACE_DNS, "zhang")
uuid.uuid4()