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):passclass StackEmptyException(Exception):passclass Stack:def __init__(self,size):self.size = sizeself.lst = []self.top = 0def push(self,el):if self.top >=self.size:raise StackFullException("超范围了")self.lst.insert(self.top,el)self.top += 1def pop(self):if self.top == 0:raise StackFullException("拿空了")self.top -= 1el = self.lst[self.top]return els = 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)

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)

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

4. functools

wraps   给装饰器中的inner改名字

reduce  归纳.

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

转载于:https://www.cnblogs.com/a2534786642/p/10182027.html

23 Python常用模块(一)相关推荐

  1. 对于python来说、一个模块就是一个文件-python常用模块

    python常用模块 什么是模块? 常见的场景:一个模块就是一个包含了python定义和声明的文件,文件名就是模块名字加上.py的后缀. 但其实import加载的模块分为四个通用类别: 1 使用pyt ...

  2. Python 常用模块总结

    Python 常用模块总结 1.random 2.math 3.os 4.os.path 5.sys 6.hashlib 7.hmac 8.time 9.datetime 10.calendar 11 ...

  3. python常用模块-调用系统命令模块(subprocess)

    python常用模块-调用系统命令模块(subprocess) 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. subproces基本上就是为了取代os.system和os.spaw ...

  4. Python 常用模块大全

    Python 常用模块大全(整理) OS 模块 #os模块就是对操作系统进行操作,使用该模块必须先导入模块: import os #getcwd() 获取当前工作目录(当前工作目录默认都是当前文件所在 ...

  5. 实战篇一 python常用模块和库介绍

    # -_-@ coding: utf-8 -_-@ -- Python 常用模块和库介绍 第一部分:json模块介绍 import json 将一个Python数据结构转换为JSON: dict_ = ...

  6. python常用模块大全总结-常用python模块

    广告关闭 2017年12月,云+社区对外发布,从最开始的技术博客到现在拥有多个社区产品.未来,我们一起乘风破浪,创造无限可能. python常用模块什么是模块? 常见的场景:一个模块就是一个包含了py ...

  7. python常用模块之shelve模块

    python常用模块之shelve模块 shelve模块是一个简单的k,v将内存中的数据通过文件持久化的模块,可以持久化任何pickle可支持的python数据类型 我们在上面讲json.pickle ...

  8. Python常用模块——目录

    Python常用模块学习 Python模块和包 Python常用模块time & datetime &random 模块 Python常用模块os & sys & sh ...

  9. Python常用模块集锦

    常用模块主要分为以下几类(缺失的后续再补充): 时间转换 时间计算 序列化和反序列化:json,pickle 编解码:unicode,base64 加解密:md5,sha1,hmac_sha1,aes ...

最新文章

  1. Python的基本语法
  2. Forefront Client Security部署前准备
  3. html追加行clone,调用clone()方法后就可以将复制的节点追加到body元素内。( ) 答案:√...
  4. mysql5.7跳过gitd_MySQL5.7在线开启/关闭GTID
  5. 给你一份长长长的 Spring Boot 知识清单(上)
  6. [转]IIS的完整控制类
  7. 菜鸟要做架构师——java性能优化之for循环
  8. ajax数据显示,使用js通用模板
  9. flex, swf 不能访问网络/本地资源
  10. 使用 json-server 作为 mock 数据
  11. 缺少网卡固件导致的网络服务异常,Can‘t load firmware file bnx2x/bnx2x-e2-7.13.15.0.fw
  12. 女士品茶——统计学如何变革了科学和生活1
  13. java十大排序算法
  14. 如何使用计算机管理员账户,Win7系统怎么开启Administrator管理员账号及权限?
  15. C++寻找数组最大值和最小值
  16. cobol .cpy文件_Visual COBOL R3:“使传统的COBOL能够部署在JVM或.NET上”。
  17. 一文读懂数据治理怎么做
  18. node php v2ex,vue2.0写的V2EX社区
  19. 字符串最长对称 java_求字符串最长对称字符串的长度(转何海涛博客)
  20. 企业网站友情链接有什么作用,毫无保留的给大家分析

热门文章

  1. springside3.3.4部署小结
  2. SP 2010: Getting started with Business Connectivity Services (BCS) in SharePoint 2010
  3. 忘记root密码如何处理
  4. 第十一周编程总结--助教
  5. mysql状态常用参数分析
  6. 字符串中连续出现最多的子串 amp; 字符串中最长反复子串
  7. Maven让资源文件处理插件能够解析资源文件中的Maven属性
  8. appium运行报错java.net.SocketException: socket write error
  9. JS 设计模式 四(单例)
  10. Android 之 ProgressDialog用法介绍(矩形进度条 和 圆形 进度条)