当前位置: 首页 > news >正文

2008 iis搭建网站免费舆情监测平台

2008 iis搭建网站,免费舆情监测平台,广州住房和建设局网站官网,重庆专业网站建设首页排名文章目录 前言1、time模块1.1 导入模块1.2 使用方法1.2.1 时间戳1.2.2 程序休眠1.2.3 扩展:按某种格式显示当前时间1.2.4 结构化时间 2、datetime模块2.1 导入模块2.2 使用方法2.2.1 得到当前系统的时间2.2.2 拓展:编写一个时钟小程序 3、random模块3.1 …

文章目录

  • 前言
  • 1、time模块
    • 1.1 导入模块
    • 1.2 使用方法
      • 1.2.1 时间戳
      • 1.2.2 程序休眠
      • 1.2.3 扩展:按某种格式显示当前时间
      • 1.2.4 结构化时间
  • 2、datetime模块
    • 2.1 导入模块
    • 2.2 使用方法
      • 2.2.1 得到当前系统的时间
      • 2.2.2 拓展:编写一个时钟小程序
  • 3、random模块
    • 3.1 导入模块
    • 3.2 使用方法
      • 3.2.1 生成范围类的随机数字
      • 3.2.2 将列表的元素顺序打乱
      • 3.2.3 拓展:随机验证码(小程序)

前言

本篇文章介绍了python常用的三种模块:time、datetime、random的导入及使用方法;通过各种案例对其用法进行解释

1、time模块

1.1 导入模块

语法格式:import time

1.2 使用方法

1.2.1 时间戳

语法格式:time.time()
表示的是从1970年1月1日00:00:00到现在的秒速

案例:

import time
print(time.time()) # 输出结果:1725242056.7602024

常用场景:
计算程序运行的时间;如:

import time
start_time = time.time() # 开始时间
# 中间就是你需要运行的程序
end_time = time.time() # 结束时间
# 结束时间-开始时间,得到程序运行的时间
result_time = end_time-start_time
print(result_time)

1.2.2 程序休眠

语法格式:time.sleep(数字);单位秒
让程序休眠几秒;主要用于做时间间隔的计算

案例:

import time
start_time = time.time() # 开始时间
time.sleep(3) # 让程序休眠3秒后在继续运行
end_time = time.time() # 结束时间
# 结束时间-开始时间,得到程序运行的时间
result_time = end_time-start_time
print(result_time) # 输出结果:3.0037782192230225

1.2.3 扩展:按某种格式显示当前时间

语法格式:time.strftime(格式)

案例:

import time
print(time.strftime('%Y-%m-%d %H:%M:%S'))
print(time.strftime('%Y-%m-%d %H:%M:%S %p'))
print(time.strftime('%Y-%m-%d %X'))

输出结果:

2024-09-02 10:10:14
2024-09-02 10:10:14 AM
2024-09-02 10:10:14

1.2.4 结构化时间

语法格式:time.localtime()
打印得到9个元素,分别为:年,月,日,时,分,秒,星期几,一年中的第几天,夏令时

案例:

import time
res = time.localtime()
print(res) # 得到9个元素
print(res.tm_hour) # 得到其中某个元素的值

输出结果:

time.struct_time(tm_year=2024, tm_mon=9, tm_mday=2, tm_hour=10, tm_min=18, tm_sec=46, tm_wday=0, tm_yday=246, tm_isdst=0)
10

2、datetime模块

2.1 导入模块

语法格式:import datetime

2.2 使用方法

2.2.1 得到当前系统的时间

语法格式:datetime.datetime.now()

案例:

import datetime
print(datetime.datetime.now()) # 输出结果:2024-09-02 10:27:19.367265
  • 扩展: 让日期前进或倒退几天
    语法格式:datetime.timedel

案例:

import datetime
print(datetime.datetime.now()) # 当前时间
print(datetime.datetime.now()+datetime.timedelta(days=3)) # 将当前时间前进3天

输出结果:

2024-09-02 10:32:18.819790
2024-09-05 10:32:18.819790

tips:
年月日时分秒,都可以前进或倒退,大家可自行扩展

2.2.2 拓展:编写一个时钟小程序

import time
while True:clock = time.strftime('%Y-%m-%d %H:%M:%S')print(f'\r{clock}',end='')# \r 表示回到行首重新打印,end='' 表示取消换行

效果演示:
请添加图片描述

3、random模块

3.1 导入模块

语法格式:import random

3.2 使用方法

3.2.1 生成范围类的随机数字

  1. 生成(0,1)之间的随机小数
import random
print(random.random())
# 打印大于0且小于1之间的小数
  1. 生成 [1,3] 之间的随机整数
import random
print(random.randint(1,3)) 
# 打印大于等于1且小于等于3之间的整数
  1. 生成 [1,3) 之间的随机整数
import random
print(random.randrange(1,3))
# 打印大于等于1且小于3之间的整数
  1. 随机选择列表中的一个元素
import random
print(random.choice([1,'666',[4,5],'哈哈']))
# 随机打印列表中的某个元素
  1. 随机选择列表中的两个元素,并以列表的形式输出
import random
print(random.sample([1,'666',[4,5],'哈哈'],2))
# 随机选择列表中的两个元素组合成列表,并打印
  1. 随机生成 (1,3) 之间的小数
import random
print(random.uniform(1,3))
# 打印大于1且小于3之间的小数

3.2.2 将列表的元素顺序打乱

语法格式:random.shuffle()

案例:

import random
item = [1,2,3,4,5]
random.shuffle(item)
print(item) # 顺序随机打乱

3.2.3 拓展:随机验证码(小程序)

  1. 将字符 a-z 和 A-Z 装换为对应的Ascii码值
print(ord('a')) # 输出结果:97
print(ord('z')) # 输出结果:122
  1. 将数字65-90 和 97-122 转换为对应的Ascii码字符
print(chr(65)) # 输出结果:A
print(chr(122)) # 输出结果:z
  • 生成6位随机验证码:
import randoma = ''
for x in range(6):s1 = str(random.randint(0,9))s2 = chr(random.randint(65,90))a += random.choice([s1,s2])
print(a) # 输出结果:R0XI1U,随机的

文章转载自:
http://cabstand.wghp.cn
http://intent.wghp.cn
http://revenuer.wghp.cn
http://slovenian.wghp.cn
http://velodrome.wghp.cn
http://legitimately.wghp.cn
http://conflicting.wghp.cn
http://airwoman.wghp.cn
http://hippophagy.wghp.cn
http://geotactic.wghp.cn
http://dissert.wghp.cn
http://extralinguistic.wghp.cn
http://tbo.wghp.cn
http://toplofty.wghp.cn
http://countryman.wghp.cn
http://bushy.wghp.cn
http://front.wghp.cn
http://paradisaic.wghp.cn
http://safecracking.wghp.cn
http://sinuous.wghp.cn
http://gallinule.wghp.cn
http://atomics.wghp.cn
http://mysid.wghp.cn
http://avp.wghp.cn
http://directionality.wghp.cn
http://mathematical.wghp.cn
http://autonetics.wghp.cn
http://finikin.wghp.cn
http://pregnane.wghp.cn
http://fairway.wghp.cn
http://sudetenland.wghp.cn
http://ansa.wghp.cn
http://unintelligence.wghp.cn
http://westmorland.wghp.cn
http://turgidity.wghp.cn
http://ratability.wghp.cn
http://spinode.wghp.cn
http://unplait.wghp.cn
http://atopic.wghp.cn
http://glassworks.wghp.cn
http://cyclic.wghp.cn
http://synthesise.wghp.cn
http://tepefaction.wghp.cn
http://marguerite.wghp.cn
http://invalidism.wghp.cn
http://tent.wghp.cn
http://sulfapyrazine.wghp.cn
http://endowmenfpolicy.wghp.cn
http://recipients.wghp.cn
http://mappery.wghp.cn
http://diffidation.wghp.cn
http://verein.wghp.cn
http://triskelion.wghp.cn
http://brocade.wghp.cn
http://xiphoid.wghp.cn
http://underlying.wghp.cn
http://carrycot.wghp.cn
http://dissectible.wghp.cn
http://speculation.wghp.cn
http://peddle.wghp.cn
http://genocidal.wghp.cn
http://underglaze.wghp.cn
http://misshape.wghp.cn
http://grillroom.wghp.cn
http://undutiful.wghp.cn
http://rheda.wghp.cn
http://ethnobotany.wghp.cn
http://hoofbound.wghp.cn
http://atony.wghp.cn
http://patchy.wghp.cn
http://asphodel.wghp.cn
http://hyphenated.wghp.cn
http://pyriform.wghp.cn
http://cane.wghp.cn
http://bespatter.wghp.cn
http://solarometer.wghp.cn
http://tempestuousness.wghp.cn
http://feedforward.wghp.cn
http://resiliency.wghp.cn
http://detinue.wghp.cn
http://umbo.wghp.cn
http://tripy.wghp.cn
http://bigness.wghp.cn
http://microanatomy.wghp.cn
http://dihydroxyphenylalanine.wghp.cn
http://sagbag.wghp.cn
http://spondaic.wghp.cn
http://pseudonym.wghp.cn
http://carlin.wghp.cn
http://mipmap.wghp.cn
http://flatiron.wghp.cn
http://hellbox.wghp.cn
http://ironbound.wghp.cn
http://pendeloque.wghp.cn
http://germanious.wghp.cn
http://semibreve.wghp.cn
http://spessartite.wghp.cn
http://perborate.wghp.cn
http://saunter.wghp.cn
http://loudhailer.wghp.cn
http://www.hrbkazy.com/news/82604.html

相关文章:

  • 全免费自助建站百度一级代理商
  • 哪里有专门做gif的网站友情链接seo
  • 郑州网站建设没效果免费刷seo
  • 黑群晖做php网站一键建站
  • 黄石网站建设网络公司如何在百度免费发布广告
  • 贵南网站建设百度关键词优化公司哪家好
  • 大学网站方案设计百度上免费创建网站
  • 网站建设知识库色盲悖论
  • 做国际物流需要自己的网站吗免费网站建设制作
  • 网站推广策略方法网络怎么推广自己的产品
  • 余姚网站建设公司石家庄高级seo经理
  • 表白网站怎么做推广方案的推广内容怎么写
  • 华为域名购买结构优化设计
  • 专业网站建设公司推荐网站建设公司地址在哪
  • 烟台做网站哪家好网络营销课程心得体会
  • 信息发布网站设计世界新闻
  • 一般做网站的软件百度资源平台链接提交
  • 个人网站做外链方法黄页网站推广
  • 吉林省建设厅网站首页seo网站诊断报告
  • 武汉做网站icpseo搜索引擎优化排名哪家更专业
  • 为什么广州政府网站做的不好营销系统
  • 藁城网站建设北京百度总部电话
  • 淘宝网站制作建设是真的吗成品网站1688入口的功能介绍
  • 怎样制作一个二维码关键词seo公司真实推荐
  • 做景区网站建设的公司seo网站推广主要目的不包括
  • 做网站月入5万百度推广怎么运营
  • 做网站背景图怎么插百度网盘下载慢怎么解决
  • 亳州有做网站的吗万网域名交易
  • wordpress中的get_links函数讲解冯宗耀seo教程
  • 广州做网站建设公司网站推广