Python教程系列(11)--常用模块

Python教程系列–常用模块

Python教程系列常用模块代码如下:

#python常用模块教程
#导入模块
#导入日期操作模块time
import time
#导入文件路径操作模块os
import os
#导入加密操作模块hashlib
import hashlib
#导入随机数操作模块random
import random

#获取当前本地时间   localtime函数用来获取本地时间
print(time.localtime())
print('............')

#将当前本地的时间按照设定的格式去展示  %Y-%m-%d %H:%M:%S 年-月-日时分秒
now=time.strftime('%Y-%m-%d %H:%M:%S',time.localtime())
#打印按照格式设定的当前时间
print(now)
print('............')

#获取文件的绝对路径地址
path = os.path.abspath(os.path.dirname('.'))
#打印当前文件的绝对路径地址信息
print(path)
print('............')

#创建md5加密对象
hash=hashlib.md5()
#设置加密数值及编码格式
hash.update(bytes('123456',encoding='utf-8'))
#执行加密操作
print(hash.hexdigest())
print('............')

#随机打印一个1-10的整数  randint用来随机整数的函数
print(random.randint(1,10))

代码结果如下:
代码结果

爱测试的小浩

猜你喜欢

转载自blog.csdn.net/qq_38484679/article/details/106122690