1. 简单了解模块

写的每一个py文件都是一个模块.

还有一些我们一直在使用的模块

buildins 内置模块. print, input

random 主要是和随机相关的内容

random()    随机小数

uninform(a,b) 随机小数

randint(a,b)  随机整数

choice() 随机选择一个

sample() 随机选择多个

shuffle() 打乱

2. Collections

1. Counter 计数器

2. defaultdict 默认值字典

3. OrderedDict 有序字典

数据结构(队列, 栈)

栈:先进后出

Stack

class StackFullException(Exception):
pass class StackEmptyException(Exception):
pass class Stack:
def __init__(self,size):
self.size = size
self.lst = []
self.top = 0 def push(self,el):
if self.top >=self.size:
raise StackFullException("超范围了")
self.lst.insert(self.top,el)
self.top += 1 def pop(self):
if self.top == 0:
raise StackFullException("拿空了")
self.top -= 1
el = self.lst[self.top]
return el s = Stack(4) s.push("我")
s.push("和")
s.push("你")
s.push("在") print(s.pop())
print(s.pop())
print(s.pop())

队列: 先进先出

Queue

import queue
q = queue.Queue()
q.put("李嘉诚1")
q.put("李嘉诚2")
q.put("李嘉诚3")
q.put("李嘉诚4")
q.put("李嘉诚5") print(q.get())
print(q.get())
print(q.get())
print(q.get())
print(q.get())


3. Time模块


 
   时间有三种:

结构化时间 gmtime()
localtime()

时间戳  time.time() 
time.mktime()

格式化时间
time.strftime() time.strptime()

时间转化:

数字
-> 字符串

struct_time = time.localtime(数字)

str = time.strftime("格式",
struct_time)

import time
a = 32536799999
t = time.localtime(a)
s = time.strftime("%Y-%m-%d %H:%M:%S",t)
print(s)

字符串 -> 数字

struct_time = time.strptime(字符串, "格式")

num = time.mktime(struct_time)

strt = input("请输入一个时间")
t = time.strptime(strt,"%Y-%m-%d %H:%M:%S")
a = time.mktime(t)
print(a)

4. functools

wraps   给装饰器中的inner改名字

reduce  归纳.

偏函数   把函数的参数固定.

最新文章

  1. 在安装AndroidStudio时产生的问题
  2. 拾取模型的原理及其在THREE.JS中的代码实现
  3. case when then else end 的用法
  4. 探秘重编译(Recompilations)(2/2)
  5. URAL 1203. Scientific Conference(瞎搞)
  6. [nowCoder] 二进制中1的个数
  7. MariaDB设置主从复制[转载]
  8. MapReduce UnitTest
  9. 2045不容易系列之(3)—— LELE的RPG难题
  10. vmware安装黑苹果教程
  11. 1.Spring Framework 5.0 入门篇
  12. Redis基础知识小结
  13. mysql 表
  14. POJ - 3468 线段树区间修改,区间求和
  15. kafka集群图形界面管理工具kafka-manager
  16. English trip EM2-PE-5A Plan a dinner party Teacher:Lamb
  17. MySQL基本教程(一)
  18. apache-日志-记录post数据
  19. FTP原理
  20. UVA 562(01背包)

热门文章

  1. JQuery | trigger() 方法
  2. 测试 | 单元测试工具 | JUnit | 参数化
  3. [51Nod1952] 栈
  4. python入门之前面内容拾遗
  5. c/c++学习系列之putchar、getchar、puts、gets的运用
  6. python_21(Django中间件)
  7. 第八章 设计用户界面 之 给Web程序应用用户界面设计
  8. Java-String字符串相关
  9. leetcode134 Gas Station
  10. Easyui combobox如何默认选中第一项???