Python3 time模块&datetime模块&random模块
'''
time模块
''' # import time
# print(help(time)) # help()提供帮助
# print(time.time()) # 1970年开始到现在的秒数(时间戳)——重点
# time.sleep(3) # CPU不工作,阻塞——重点
# print(time.clock()) # 计算CPU工作时间
#
# # 结构化(元组形式)
# print(time.gmtime()) # 格里尼治天文台时间,标准时间——重点
# # time.struct_time(tm_year=2017, tm_mon=10, tm_mday=18, tm_hour=1, tm_min=56, tm_sec=47, tm_wday=2, tm_yday=291, tm_isdst=0)
# print(time.localtime()) # 本地时间——重点
# a1 = time.localtime()
# print(time.strftime('%Y-%m-%d %H:%M:%S',a1)) # 自定义时间显示样式——重点
# print(time.strptime('2017-09-08 10:21:10','%Y-%m-%d %H:%M:%S')) # 转换为结构化时间,前后的格式要一一对应,各市要相同
# # 重点
# print(time.ctime()) # 当前时间(格式不能动),参数默认为空,加入参数后,将参数转换为时间,从1970年算起
# print(time.mktime(time.localtime())) # 转化为时间戳 '''
datetime 模块
'''
# import datetime
# print(datetime.datetime.now()) # 显示现在时间 '''
random 模块
'''
# import random
#
# print(random.random()) # 随机生成数,random()——默认范围是0-1
# print(random.randint(1,8)) # 范围1-8
# print(random.choice('hello')) # 随机选择
# print(random.choice([123,'asd',[1,2]])) # 随机选择元素
# # print(random.sample([123,'asd'],1,44)) # TypeError: sample() takes 3 positional arguments but 4 were given
# print(random.sample([123,'asd'],1)) # 正确
# print(random.randrange(1,5)) # range 取值取不到5,范围1-4
#
#
# # 验证码函数
# # version--1
# def rand_code():
# code = ''
#
# for i in range(5):
# if i == random.randint(0,4):
# add = random.randrange(10)
# else:
# add = chr(random.randrange(65,91))
# code += str(add)
# print(code)
# rand_code()
#
# # version--2
# def fun1():
# code = ''
# for i in range(5):
# add = random.choice([random.randrange(10),chr(random.randrange(65,91))])
# code += str(add)
# print(code)
# fun1()
Python3 time模块&datetime模块&random模块的更多相关文章
- Python包,json&pickle,time&datetime,random模块
补充内容: 解决模块循环导入的两种方法:(不得已而为之,表示程序结构不够严谨) 将导入模块语句放在文件最下方 保证语句导入之前函数内代码能够被执行 将导入语句放进函数体内 使其不影响整个函数的运行 包 ...
- collections、time、datetime、random模块
今日内容概要 1.re模块的其他知识 2.正则起别名与分组机制 3.collections模块 4.time与datetime模块 5.random随机数模块 今日内容详细 re模块的其他知识 imp ...
- 【python标准库模块二】random模块学习
random模块是用来生成随机数的模块 导入random模块 import random 生成一个0~1的随机数,浮点数 #随机生成一个0~1的随机数 print(random.random()) 生 ...
- os模块和sys模块,以及random模块
os模块 os模块是与操作系统交互的一个接口 os.getcwd() 获取当前工作目录,即当前python脚本工作的目录路径 os.chdir("dirname") 改变当前脚本工 ...
- 常用模块一(random模块、time模块、sys模块)
一.random模块 import random # 1 取随机小数 应用:数学计算 ret = random.random() # 大于0且小于1之间的小数 print(ret) # 0.53559 ...
- 17,时间模块 time,random模块
表示时间的三种方式 在python中,通常有着三种方式来表示时间:时间戳,元祖,格式化的时间字符串: 1,时间戳(timestamp):通常来说时间戳表示的是从1970年1月1日00:00:00开始按 ...
- day13 函数模块之序列化 random 模块 os模块 sys模块 hashlib模块 collections模块
json import json dic = {'k1':'v1','k2':'v2','k3':'v3'} str_dic = json.dumps(dic) #序列化:将一个字典转换成一个字符串 ...
- Python入门-模块2(random模块、os模块)
>>> random.randomrange(1,10) #返回1-10之间的一个随机数,不包括10 >>> random.randint(1,10) #返回1-1 ...
- Python之数据加密与解密及相关操作(hashlib模块、hmac模块、random模块、base64模块、pycrypto模块)
本文内容 数据加密概述 Python中实现数据加密的模块简介 hashlib与hmac模块介绍 random与secrets模块介绍 base64模块介绍 pycrypto模块介绍 总结 参考文档 提 ...
- 函数和常用模块【day06】:random模块(三)
本节内容 1.简述 2.random模块 3.string模块 4.生成随机数 一.简述 我们经常会使用一些随机数,或者需要写一些随机数的代码,今天我们就来整理随机数模块:random模块 二.ran ...
随机推荐
- iBrand 开源电商小程序 (Laravel API+ webpack + gulp + 原生小程序)
iBrand 社交电商产品正式进入开源过程中了,我们制定了详细的开源计划,目前已经发布了 V1 的版本,后续的版本也在陆续整理完善中. 各个版本功能明细如下图: 3 个版本计划在今年春节前全部完成,可 ...
- HCNA-RIP定时器
1.拓扑图 2. 1.RIP有哪些定时器?三种:更新定时器.老化定时器.垃圾回收定时器 2.RIP的定时器有哪些作用?更新定时器(30s):运行RIP的路由器会以30s为周期,向邻居发送RIP路由.老 ...
- Spring中<context:annotation-config/>的作用
spring中<context:annotation-config/>配置的作用,现记录如下: <context:annotation-config/>的作用是向Spring容 ...
- tensorflow ImportError: libmklml_intel.so: cannot open shared object file: No such file or directory
通过whl文件安装 tensorflow,显示缺少libmklml_intel.so 需要 1)安装intel MKL库 https://software.intel.com/en-us/articl ...
- ZT在谷歌上班感受如何?
在谷歌上班感受如何? 2013-11-05 作者:腾讯科技 出处: 互联网 责编:zlu 在谷歌这家全球最大最有抱负的技术公司工作将是怎样的情景呢?是天堂般的享受,还是地狱般的折磨呢?下面看一 ...
- python入门8 输入输出
输入 input() 输出 print() #coding:utf-8 #/usr/bin/python """ 2018-11-03 dinghanhua 输入输出 & ...
- NEUACM1132: Renew MST Quickly 增量最小生成树
题目链接:http://acm.neu.edu.cn/hustoj/problem.php?id=1132 和UVa11354很类似 题意: 原先有一棵树,每次加一条边,看最小生成树大小: 这个和增量 ...
- bpexpdate – 更改映像目录库中备份的截止日期以及介质目录库中介质的截止日期nbu
1.根据bpdbjobs查找backupidbpdbjobs -jobid xxx -all_columns|grep backupid 2.查看数据保留时间[root@backup]# bpimag ...
- POJ 1632 Vase collection【状态压缩+搜索】
题目传送门:http://poj.org/problem?id=1632 Vase collection Time Limit: 1000MS Memory Limit: 10000K Total ...
- HDU 1175 连连看(超级经典的bfs之一)
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1175 连连看 Time Limit: 20000/10000 MS (Java/Others) ...