python常见内置模块

一、sys模块:
sys.argv():在Python脚本传参使用
在这里插入图片描述
sys.exit():系统退出
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述sys.getdefaultencoding:获取系统默认编码

getfilesystemencoding: 获取文件编码
getrecursionlimit():获取系统默认递归的最大层数
setrecursionlimit(num):设置递归的最大层数
getrefcount():获取对象的引用计数的数量
二、hashlib:加密,散列加密(hash加密)
根据加密是否可逆可分为:
1、可逆加密
根据加密和解密的秘钥是否是同一个可分为:
(1)对称加密:DES
(2)非对称加密:RSA
2、不可逆加密(hash是典型的不可逆加密)
加密方式:MD5、shal256
例如:
import hashlib
md5 = hashlib.md5(“需要加密的数据”.encode(“utf-8”)) 在这里插入图片描述
三、base64模块
1、 b64encode() # 查找资料,完成自学
2、 b64decode()
四、time模块:
1、asctime():获取系统当前时间
2、ctime():获取系统当前时间
3、 time():获取当前的时间戳
4、localtime():返回当前时间,以类似于元组的对象
t = time.localtime()
print(“当前时间是%s-%s-%s %s:%s:%s” %(t.tm_year, t.tm_mon, t.tm_mday, t.tm_hour, t.tm_min, t.tm_sec))
5、time.strftime():将时间对象格式化成字符串
time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
6、time.strptime():时间字符串转换为时间对象
time.strptime(‘2019/09/18 21:02:44’, “%Y/%m/%d %H:%M:%S”)
五、calendar 日历模块
datetime
datetime.datetime.now():获取系统当前时间

发布了65 篇原创文章 · 获赞 3 · 访问量 1778

猜你喜欢

转载自blog.csdn.net/weixin_44077638/article/details/101036128