2025年Python(一)——Python标准库

Python(一)——Python标准库Pythonb 标准库 1 time 库 import time print time localtime print time gmtime 结果 time ctime 结果 t1 start time time t2 start time

大家好,我是讯享网,很高兴认识大家。

Pythonb标准库

1.time库

在这里插入图片描述

import time print(time.localtime()) print(time.gmtime()) 
讯享网

结果:
在这里插入图片描述time.ctime()
结果:
在这里插入图片描述在这里插入图片描述

讯享网t1_start=time.time() t2_start=time.perf_counter() t3_start=time.process_time() print(t1_start) print(t2_start) print(t3_start) res=0 for i in range(): res+=i time.sleep(5) t1_end=time.time() t2_end=time.perf_counter() t3_end=time.process_time() print("time:{:.3f}秒".format(t1_end-t1_start)) print("ime.perf_counter:{:.3f}秒".format(t2_end-t2_start)) print("time.process_time:{:.3f}秒".format(t3_end-t3_start)) 

结果:
在这里插入图片描述

random库

在这里插入图片描述

from random import * seed(10) print(random()) seed(10) print(random()) print(random()) 

结果:
在这里插入图片描述在这里插入图片描述在这里插入图片描述

collections库——容器数据类型

1.namedtuple——具名元组
在这里插入图片描述在这里插入图片描述

讯享网import collections p=(1,2) Point = collections.namedtuple("Point",["x","y"]) p=Point(1,y=2) p 

结果:
在这里插入图片描述2.couter——计数器工具

from collections import Counter s="sdfhbcsdvvporsjpas" str_s=Counter(s) print(str_s) 

结果:
在这里插入图片描述3。deque——双向队列
在这里插入图片描述

itertools库——迭代器

1.排列组合迭代器
(1)product——笛卡尔积
(2)permutation——排列
(3)combinations——组合
(4)combinations_with_replacement——元素可重复组合
2.拉链
(1)zip
(2)zip_longest——长拉链
3.无穷迭代器
(1)count(start=o,step=1)——计数
(2)cycle(iterable)——循环
(3)repeat(object[,times])——重复
4.其它
(1)chain(iterables)——锁链
(2)enumerable(iterable,start=0)——枚举(Python内置)
(3)groupby(iterable,key=None)——分组

总结

在这里插入图片描述在这里插入图片描述在这里插入图片描述在这里插入图片描述

小讯
上一篇 2025-03-12 21:59
下一篇 2025-02-11 10:36

相关推荐

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容,请联系我们,一经查实,本站将立刻删除。
如需转载请保留出处:https://51itzy.com/kjqy/82160.html