1.random()模块的使用

import random

x = random.random()
y = random.random() print(x,y*10)
#random.random()随机生成一个[0,1)之间的随机数 m = random.randint(0,10)
print(m)
#random.randint()随机生成一个[0:10]之间的整数 st1 = random.choice(list(range(10)))
st2 = random.choice('adadfaifhasui')
print(st1,st2) lst= list(range(20))
sli = random.sample(lst,5)
print(sli)
#random.sample(a,b)随机获取a中指定b长度的片段 lst = [1,2,4,5,6,9]
random.shuffle(lst)
print(lst)
#random.shuffle()将一个列表内的元素打乱

以上程序输出结果:

0.7595010075157713 4.853087162748832
8
4 a
[15, 6, 12, 5, 16]
[6, 9, 2, 4, 1, 5]

2.time模块的使用

import time
for i in range(2):
print("hello")
time.sleep(1) #每隔1秒输出hello,输出两遍
#time.sleep(1)程序休息1秒 print(time.ctime())
print(type(time.ctime()))
#将当前时间转化为一个字符串 print(time.localtime())
print(type(time.localtime()))
#将当前时间转化为当前时区的struct_time
#wday 0-6表示周一到周日
#yday 1-366 一年中的第几天
#isdst 是否为夏令时 默认为-1 print(time.strftime('%Y-%m-%d %H:%M:%S',time.localtime()))
#time.strftime(a,b)
#a为格式化字符串格式
#b为时间戳,一般用localtime()

以上程序的输出结果:

hello
hello
Sat Nov 3 12:18:38 2018
<class 'str'>
time.struct_time(tm_year=2018, tm_mon=11, tm_mday=3, tm_hour=12, tm_min=18, tm_sec=38, tm_wday=5, tm_yday=307, tm_isdst=0)
<class 'time.struct_time'>
2018-11-03 12:18:38

%y 两位数的年份表示(00-99)

%Y 四位数的年份表示(000-9999)

%m 月份(01-12)

%d 月内中的一天(0-31)

%H 24小时制小时数(0-23)

%I 12小时制小时数(01-12)

%M 分钟数(00=59)

%S 秒(00-59)

%a 本地简化星期名称

%A 本地完整星期名称

%b 本地简化的月份名称

%B 本地完整的月份名称

%c 本地相应的日期表示和时间表示

%j 年内的一天(001-366)

%p 本地A.M.或P.M.的等价符

%U 一年中的星期数(00-53)星期天为星期的开始

%w 星期(0-6),星期天为星期的开始

%W 一年中的星期数(00-53)星期一为星期的开始

%x 本地相应的日期表示

%X 本地相应的时间表示

%Z 当前时区的名称

%% %号本身

random模块 time模块的用法 python的更多相关文章

  1. python 全栈开发,Day27(复习, defaultdict,Counter,时间模块,random模块,sys模块)

    一.复习 看下面一段代码,假如运行结果有问题,那么就需要在每一步计算时,打印一下结果 b = 1 c = 2 d = 3 a = b+c print(a) e = a + d print(e) 执行输 ...

  2. Python 常用模块(1) -- collections模块,time模块,random模块,os模块,sys模块

    主要内容: 一. 模块的简单认识 二. collections模块 三. time时间模块 四. random模块 五. os模块 六. sys模块 一. 模块的简单认识 模块: 模块就是把装有特定功 ...

  3. Python模块01/自定义模块/time模块/datetime模块/random模块

    Python模块01/自定义模块/time模块/datetime模块/random模块 内容大纲 1.自定义模块 2.time模块 3.datetime模块 4.random模块 1.自定义模块 1. ...

  4. 小白的Python之路 day5 configparser模块的特点和用法

    configparser模块的特点和用法 一.概述 主要用于生成和修改常见配置文件,当前模块的名称在 python 3.x 版本中变更为 configparser.在python2.x版本中为Conf ...

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

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

  6. python笔记-1(import导入、time/datetime/random/os/sys模块)

    python笔记-6(import导入.time/datetime/random/os/sys模块)   一.了解模块导入的基本知识 此部分此处不展开细说import导入,仅写几个点目前的认知即可.其 ...

  7. python常用模块: random模块, time模块, sys模块, os模块, 序列化模块

    一. random模块  import random # 任意小数 print(random.random()) # 0到1的任意小数 print(random.uniform(-10, 10)) # ...

  8. Python常用模块-随机数模块(random)

    Python常用模块-随机数模块(random) 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.常用方法举例 #!/usr/bin/env python #_*_coding: ...

  9. python之模块pprint之常见用法

    # -*- coding: cp936 -*- #python 27 #xiaodeng #python之模块pprint之常见用法 import pprint data = [(1,{'a':'A' ...

  10. python之模块poplib之常见用法

    # -*- coding: cp936 -*- #python 27 #xiaodeng #python之模块poplib之常见用法 ''' 所以,收取邮件分两步: 第一步:用poplib把邮件的原始 ...

随机推荐

  1. Smile with face. Smile with mind.

    Smile with face. Smile with mind.微笑不仅是挂在脸上的,更是发自心底的.

  2. easyui datagrid 动态加载数据 渲染问题,表格错位问题

    $('#dg').datagrid({ url:'datagrid_data.json', columns:[[ {field:'code',title:'Code',width:100}, {fie ...

  3. ps_cc:制作sprite拼贴图片

    我们的目标是: 将   合并为一张图片   step1:制作动作,便于批处理和重复使用 首先随便新建空白文档(建议:90x300px) 录制动作,alt+F9   上图中,可以新建分组前端,再新建动作 ...

  4. <Android 基础(十)> FloatingActionButton

    介绍 Source Code中的介绍如下: Floating action buttons are used for a special type of promoted action. They a ...

  5. 如何解决ArcGIS Runtime SDK for Android中文标注无法显示的问题

    自10.2版本开始,我就一直被ArcGIS Runtime SDK for Android的中文标注无限困扰.无论是驻留于内存中的Graphic 的文本符号TextSymbol,还是新增的离线geod ...

  6. selenium 服务器端运行命令

    cd C:\Users\kfa_wangchao\Downloadsjava -jar selenium-server-standalone-2.37.0.jarcmd=getNewBrowserSe ...

  7. 易客CRM-3.0.4 (OpenLogic CentOS 6.5)

    平台: CentOS 类型: 虚拟机镜像 软件包: apache1.3.8 centos6.5 mysql5.1.72 php5.2.17 commercial crm linux 服务优惠价: 按服 ...

  8. Swagger2:常用注解说明

    Swagger2常用注解说明 Spring Boot : Swagger 2使用教程:https://www.cnblogs.com/JealousGirl/p/swagger.html 这里只讲述@ ...

  9. jQuery-prepend、append、before、after的区别

    举例说明,原始html代码如下: <ol> <li>List item 1</li> <li>List item 2</li> <li ...

  10. 是否应该提供一个dao.insertIgnoreNull ? (像updateIgnoreNull一样)

     是否应该提供一个dao.insertIgnoreNull ? (像updateIgnoreNull一样)  发布于 406天前  作者 SayingCode  153 次浏览  复制  上一个帖子  ...