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)

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  归纳.

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

python常用模块-01的更多相关文章

  1. python 常用模块之random,os,sys 模块

    python 常用模块random,os,sys 模块 python全栈开发OS模块,Random模块,sys模块 OS模块 os模块是与操作系统交互的一个接口,常见的函数以及用法见一下代码: #OS ...

  2. python常用模块之时间模块

    python常用模块之时间模块 python全栈开发时间模块 上次的博客link:http://futuretechx.com/python-collections/ 接着上次的继续学习: 时间模块 ...

  3. Python常用模块-时间模块(time&datetime)

    Python常用模块-时间模块(time & datetime) 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.初始time模块 #!/usr/bin/env pyth ...

  4. python常用模块之time&datetime模块

    python常用模块之time&datetime模块 在平常的代码中,我们经常要与时间打交道.在python中,与时间处理有关的模块就包括:time和datetime,下面分别来介绍: 在开始 ...

  5. Python常用模块大全

    Python常用模块大全 os模块: os.remove() 删除文件 os.unlink() 删除文件 os.rename() 重命名文件 os.listdir() 列出指定目录下所有文件 os.c ...

  6. Python常用模块sys,os,time,random功能与用法,新手备学。

    这篇文章主要介绍了Python常用模块sys,os,time,random功能与用法,结合实例形式分析了Python模块sys,os,time,random功能.原理.相关模块函数.使用技巧与操作注意 ...

  7. Python常用模块之sys

    Python常用模块之sys sys模块提供了一系列有关Python运行环境的变量和函数. 常见用法 sys.argv 可以用sys.argv获取当前正在执行的命令行参数的参数列表(list). 变量 ...

  8. Python常用模块中常用内置函数的具体介绍

    Python作为计算机语言中常用的语言,它具有十分强大的功能,但是你知道Python常用模块I的内置模块中常用内置函数都包括哪些具体的函数吗?以下的文章就是对Python常用模块I的内置模块的常用内置 ...

  9. python——常用模块2

    python--常用模块2 1 logging模块 1.1 函数式简单配置 import logging logging.debug("debug message") loggin ...

随机推荐

  1. centos 安装oracle 11g r2(三)-----表空间创建

    centos 安装oracle 11g r2(三)-----表空间创建 创建表空间前要保证监听与数据库实例已经启动 1.启动监听 [oracle@localhost ~]$ lsnrctl start ...

  2. UI的设计,适配器,以及RecyclerView无法加载的解决办法

    这本书里讲到的界面设计都是用最基本的方式实现的,即编写xml文件 所有的控件都具有宽度和高度属性,即android:layout_width和android:layout_height,这两个属性对应 ...

  3. 安装MySQL-python时报错

    (py27) [root@test SimpletourDevops]# pip install MySQL-python DEPRECATION: Python 2.7 will reach the ...

  4. java.io.IOException: Stream closed解决办法

    1.出现这个bug的大体逻辑代码如下: private static void findMovieId() throws Exception { File resultFile = new File( ...

  5. 自测 基础 js 脚本。

    <html> <head> <script> //function(<text>a{[]}lert('x')</text>)() docum ...

  6. spring 后处理器

    Bean后处理器 新建maven项目并添加spring依赖,目录结构如下 Axe public interface Axe { public String chop(); } Person publi ...

  7. 使用vue开发微信公众号下SPA站点的填坑之旅

    原文发表于本人博客,点击进入使用vue开发微信公众号下SPA站点的填坑之旅 本文为我创业过程中,开发项目的填坑之旅.作为一个技术宅男,我的项目是做一个微信公众号,前后端全部自己搞定,不浪费国家一分钱^ ...

  8. Chapter 3 Phenomenon——24

    My mom was in hysterics, of course. 我的母亲当时是歇斯底里的发疯了. I had to tell her I felt fine at least thirty t ...

  9. Nginx限制访问次数和并发数

    Nginx限制访问速率和最大并发连接数模块--limit (防止DDOS攻击) http: ##zone=one或allips 表示设置名为"one"或"allips&q ...

  10. Inno Setup中多语言时,使用占位符填充

    如在: [CustomMessages] CreateDesktopIcon=Create a Desktop icon NameAndVersion=%1 version %2 普通的获取Custo ...