python 的其他模块
math模块
ceil 向上取整
floor 向下取整
pow 求幂次方
sqrt 开根号
random模块(随机数的模块)
random.random 获取一个0-1随机数
random.randint(a,b) 获取a - b之间的随机数
sys模块
sys.argv 在Python脚本传参使用(列表形式输入,空格之后)
sys.exit 系统退出
sys.getdefaultencoding 获取系统默认编码
getfilesystemencoding 获取文件编码
getrecursionlimit 获取系统默认递归的最大层数
setrecursionlimit(num) 设置递归的最大层数
getrefcount 获取对象的引用计数的数量(堆中数据在栈中对应的变量个数)
hashlib 散列加密(hash加密)
加密算法分类(加密是否可逆):
可逆加密 根据加密和解密的秘钥是否是同一个
对称加密 DES
非对称加密 RSA
不可逆加密
!!!hash是典型的不可逆加密
MD5、shal256
使用方法:
import hashlib
a = hashlib.md5(“需要加密的数据”.encode(“utf-8”))
update 在密码后加上盐值,从而当密码被**时,也无法知道真实密码
hmac 加密(用于加密数据)无法**
base64模块
b64encode编码能把图片转换为字符串
b64decode解码
time模块
asctime 获取系统当前时间
ctime 获取系统当前时间
time 获取当前的时间戳
localtime 返回当前时间,以类似于元组的对象
sleep 代码停止一定时间
strftime 将时间对象格式化成字符串
strptime 时间字符串转换为时间对象
os.system()执行 任何命令!!!
calendar 日历模块
import calendar
calendar 获取指定年份的日历字符串
month 获取指定月份的日历字符串
monthcalendar 获取指定月份的信息列表
isleap 检测年份是否是润年 如果不是100的整数倍,能被4整除就是润年,如果是100的整数倍,能被400整除就是润年
leapdays 检测指定年限内润年的数量
monthrange 获取指定月份的信息
weekday 根据指定的年月日计算星期几
timegm 将时间元组转化为时间戳
使用print()输出可换行