python常用模块-01
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的更多相关文章
- python 常用模块之random,os,sys 模块
python 常用模块random,os,sys 模块 python全栈开发OS模块,Random模块,sys模块 OS模块 os模块是与操作系统交互的一个接口,常见的函数以及用法见一下代码: #OS ...
- python常用模块之时间模块
python常用模块之时间模块 python全栈开发时间模块 上次的博客link:http://futuretechx.com/python-collections/ 接着上次的继续学习: 时间模块 ...
- Python常用模块-时间模块(time&datetime)
Python常用模块-时间模块(time & datetime) 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.初始time模块 #!/usr/bin/env pyth ...
- python常用模块之time&datetime模块
python常用模块之time&datetime模块 在平常的代码中,我们经常要与时间打交道.在python中,与时间处理有关的模块就包括:time和datetime,下面分别来介绍: 在开始 ...
- Python常用模块大全
Python常用模块大全 os模块: os.remove() 删除文件 os.unlink() 删除文件 os.rename() 重命名文件 os.listdir() 列出指定目录下所有文件 os.c ...
- Python常用模块sys,os,time,random功能与用法,新手备学。
这篇文章主要介绍了Python常用模块sys,os,time,random功能与用法,结合实例形式分析了Python模块sys,os,time,random功能.原理.相关模块函数.使用技巧与操作注意 ...
- Python常用模块之sys
Python常用模块之sys sys模块提供了一系列有关Python运行环境的变量和函数. 常见用法 sys.argv 可以用sys.argv获取当前正在执行的命令行参数的参数列表(list). 变量 ...
- Python常用模块中常用内置函数的具体介绍
Python作为计算机语言中常用的语言,它具有十分强大的功能,但是你知道Python常用模块I的内置模块中常用内置函数都包括哪些具体的函数吗?以下的文章就是对Python常用模块I的内置模块的常用内置 ...
- python——常用模块2
python--常用模块2 1 logging模块 1.1 函数式简单配置 import logging logging.debug("debug message") loggin ...
随机推荐
- mongoose入门
概述 像Mysql和Mongodb这样的数据库,一般都是在命令行或者工具里面进行操作,如果想在node搭建的服务器上面操作,就必须要利用特殊的模块的.其中操作Mongodb数据库需要用到mongoos ...
- 移动一根火柴使等式成立js版本
<html><head><meta http-equiv="Content-Type" content="text/html; charse ...
- [Umbraco] Data Types介绍
Data Types是在建立document type时需要用到的,系统自带了很多用于开发的类型,如常用的下拉列表dropdown, textbox, radiobox, checkbox以及上传,h ...
- C语言写了一个socket client端,适合windows和linux,用GCC编译运行通过
////////////////////////////////////////////////////////////////////////////////* gcc -Wall -o c1 c1 ...
- android开发学习——day1
了解安卓系统架构:Linux内核层,系统运行层库,应用框架层,应用层 版本信息 android开发的特色之处就在于强大的组件功能 开发环境android stdio 2.0安装:把安装的组件都勾选上, ...
- TDD并不是看上去的那么美
原文:http://coolshell.cn/articles/3649.html 春节前的一篇那些炒作过度的技术和概念中对敏捷和中国ThoughtWorks的微辞引发了很多争议,也惊动了中国Thou ...
- Google Optimization Tools介绍
Google Optimization Tools(OR-Tools)是一款专门快速而便携地解决组合优化问题的套件.它包含了: 约束编程求解器. 简单而统一的接口,用于多种线性规划和混合整数规划求解, ...
- Android开发艺术探索学习笔记(四)
第四章 View的工作原理 4.1初识ViewRoot和DecorView ViewRoot是连接WindowManager和DecorView的纽带,View的三大流程均是通过ViewRoot来完成 ...
- 全网最详细的启动Kafka服务时出现kafka.common.InconsistentBrokerIdException: Configured brokerId 3 doesn't match stored brokerId 1 in meta.properties错误的解决办法(图文详解)
不多说,直接上干货! 问题详情 执行bin/kafka-server-start.sh config/server.properties 时, [kfk@bigdata-pro03 kafka_2.- ...
- T-SQL 分布式查询
--返回本地服务器中定义的链接服务器列表. EXEC sys.sp_linkedservers /* 创建或更新 SQL Server 本地实例上的登录名与远程服务器中安全帐户之间的映射. 当用户登录 ...