22 内置常用模块01

今日主要内容
1. 简单了解模块
你写的每一个py文件都是一个模块.
还有一些我们一直在使用的模块
buildins 内置模块. print, input

random 主要是和随机相关的内容
random() 随机小数
uniform(a,b) 随机小数

randint(a,b) 随机整数

choice() 随机选择一个
sample() 随机选择多个

shuffle() 打乱

2. Collections
1. Counter 计数器
2. defaultdict 默认值字典
3. OrderedDict 有序字典
数据结构(队列, 栈(重点))

栈:先进后出
Stack

队列: 先进先出
Queue

3. Time模块
时间有三种:
结构化时间 gmtime() localtime()
时间戳 time.time() time.mktime()
格式化时间 time.strftime() time.strptime()

时间转化:
数字 -> 字符串
struct_time = time.localtime(数字)
str = time.strftime("格式", struct_time)

字符串 -> 数字
struct_time = time.strptime(字符串, "格式")
num = time.mktime(struct_time)

4. functools
wraps 给装饰器中的inner改名字
reduce 归纳.
偏函数 把函数的参数固定.

1.random
2.counter
3.默认值字典
4.栈和队列,双向队列
5.时间
6.functools



猜你喜欢

转载自www.cnblogs.com/work14/p/10187597.html