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

开源门户网站cms下载百度app最新版并安装

开源门户网站cms,下载百度app最新版并安装,上海建站网,免费动态网站作业模板一、random模块 random 模块用来创建随机数的模块。 random.random() # 随机生成一个大于0且小于1之间的小数 random.randint(a, b) # 随机生成一个大于等于a小于等于b的随机整数 random.uniform(a, b) …

一、random模块

  random 模块用来创建随机数的模块。

random.random()                                 # 随机生成一个大于0且小于1之间的小数
random.randint(a, b)                            # 随机生成一个大于等于a小于等于b的随机整数
random.uniform(a, b)                            # 随机生成一个大于等于a小于等于b的随机浮点数
random.choice(seq)                              # 随机选择一个seq序列中的成员
random.sample(population, k, *, counts=None)    # 随机选择多个成员
random.shuffle(x)                               # 将序列顺序随机打乱
import randomresult = random.random()                        # 随机生成一个大于0且小于1之间的小数
print("result: ",result)result = random.randint(10,20)                  # 随机生成一个大于等于a小于等于b的随机整数
print("result: ",result)result = random.uniform(10,20)                  # 随机生成一个大于等于a小于等于b的随机浮点数
print("result: %f" %result)result = random.choice([11,22,33,44,55])        # 随机选择一个seq序列中的成员
print(f"result: {result}")result = random.sample([11,22,33,44,55],3)      # 随机选择多个成员
print(f"result: {result}")num_list = [11,22,33,44,55]
random.shuffle(num_list)                        # 将序列顺序随机打乱
print("result: {}".format(num_list))

二、hashlib模块

  hashlib 模块可以用来实现加密。

hashlib.md5(str)               # 用于实现MD5加密
import hashlibdata = "Sakura"
obj = hashlib.md5("小樱".encode("utf-8"))           # 加盐
obj.update(data.encode("utf-8"))
result = obj.hexdigest()
print(result)                                       # 密文

三、json模块

  json 本质上是一个特定结构的字符串,它用于打通不同编程语言之间相互进行通信时的数据格式问题。Python 中默认转换为 json 的类型有 字符串、数值类型、列表、元组、字典、布尔值 和 None。其中,元组转换为 json 类型 () 会变为 [],None 转换为 json 会变为 null,Flase 和 True 转换为 json 会变为 flase 和 true。

  • 序列化:将 Python 数据类型转换为 JSON 格式字符串
  • 反序列化:将 JSON 格式字符串转换为 Python 数据类型
json.dumps(obj)          # 得到json格式的字符串
json.loads(obj)          # json格式的字符串转换为字典
json.dump(obj,fp)        # 将json格式的字符串写入到文件
json.load(obj,fp)        # 将文件中的json格式的字符串转换为字典
import jsoninfo = {"name":"小樱","age":10}data_json = json.dumps(info,ensure_ascii=False,indent=4)            # 序列化
print(data_json)
print(type(data_json))data_dict = json.loads(data_json)                                   # 反序列化
print(data_dict)
print(type(data_dict))
import jsoninfo = {"name":"小樱","age":10}with open("info.json",mode="w",encoding="utf-8") as f:json.dump(info,f,ensure_ascii=False)with open("info.json",mode="r",encoding="utf-8") as f:data_dict = json.load(f)print(data_dict)

  如果我们传入其它的对象类型,可能会转换 json 格式出错,此时,我们可以显示的转换为字符串类型来解决这个问题。

import json
from datetime import datedata_list = [{"name":"Sakura","age":10,"birth":date(1986,1,1).strftime("%Y-%m-%d")},{"name":"Mikoto","age":14,"brith":date(1995,5,2).strftime("%Y-%m-%d")}
]jsoon_data = json.dumps(data_list,ensure_ascii=False)
print(jsoon_data)

  我们也可以自定义类继承 JSONEncoder 类来实现序列化。

import json
from json import JSONEncoder
from datetime import datedata_list = [{"name":"Sakura","age":10,"birth":date(1986,1,1)},{"name":"Mikoto","age":14,"brith":date(1995,5,2)}
]class MyJSONEncoder(JSONEncoder):def default(self, o):# 判断o的类型if type(o) == date:return o.strftime("%Y-%m-%d")return super().default(o)jsoon_data = json.dumps(data_list,ensure_ascii=False,cls=MyJSONEncoder)
print(jsoon_data)

四、time模块与datetime模块

time.time()                                                                                           # 获取时间戳
time.sleep(secs)                                                                                      # 睡眠secs秒
datetime.datetime.now()                                                                               # 获取当前时间
datetime.timedelta(days=0, seconds=0, microseconds=0, milliseconds=0, minutes=0, hours=0, weeks=0)    # 运算加减指定时间
import timet1 = time.time()
print(t1)time.sleep(1)t2 = time.time()
print(t2-t1)
import datetimeday1 = datetime.datetime.now()
print(day1)day2 = day1 + datetime.timedelta(days=3)
print(day2)day3 = day1 + datetime.timedelta(weeks=-1)
print(day3)

【1】字符串 --> datetime 类型

from datetime import datetimetext = "1986-04-01"date = datetime.strptime(text,"%Y-%m-%d")
print(date)
print(type(date))

【2】、datetime 类型 --> 字符串

from datetime import datetimedate = datetime.now()str = date.strftime("%Y-%m-%d")
print(str)
print(type(str))

【3】、时间戳 --> datetime 类型

import time
from datetime import datetimet1 = time.time()
date = datetime.fromtimestamp(t1)
print(date)
print(type(date))

【4】、datetime 类型 --> 时间戳

from datetime import datetimedate = datetime.now()
t1 = date.timestamp()
print(t1)
print(type(t1))

文章转载自:
http://again.mnqg.cn
http://groundmass.mnqg.cn
http://excerpt.mnqg.cn
http://kryzhanovskite.mnqg.cn
http://esclandre.mnqg.cn
http://touchy.mnqg.cn
http://shilka.mnqg.cn
http://floeberg.mnqg.cn
http://tyke.mnqg.cn
http://iasi.mnqg.cn
http://improbity.mnqg.cn
http://sinuiju.mnqg.cn
http://inquisition.mnqg.cn
http://precentor.mnqg.cn
http://perennial.mnqg.cn
http://turkophobe.mnqg.cn
http://sparrowgrass.mnqg.cn
http://flake.mnqg.cn
http://gibberish.mnqg.cn
http://shvartze.mnqg.cn
http://transformable.mnqg.cn
http://discourteously.mnqg.cn
http://celebration.mnqg.cn
http://seamanlike.mnqg.cn
http://ahorse.mnqg.cn
http://towards.mnqg.cn
http://affine.mnqg.cn
http://idiochromatic.mnqg.cn
http://asio.mnqg.cn
http://forb.mnqg.cn
http://velsen.mnqg.cn
http://photoneutron.mnqg.cn
http://arachnephobia.mnqg.cn
http://permafrost.mnqg.cn
http://kalmuck.mnqg.cn
http://sindolor.mnqg.cn
http://destructible.mnqg.cn
http://smiercase.mnqg.cn
http://zonian.mnqg.cn
http://tectonization.mnqg.cn
http://voyeuristic.mnqg.cn
http://myriad.mnqg.cn
http://approachability.mnqg.cn
http://templar.mnqg.cn
http://unseasoned.mnqg.cn
http://plurally.mnqg.cn
http://hoedown.mnqg.cn
http://pyrethrin.mnqg.cn
http://hothouse.mnqg.cn
http://ramallah.mnqg.cn
http://cerebra.mnqg.cn
http://panplegia.mnqg.cn
http://authorization.mnqg.cn
http://gori.mnqg.cn
http://autoexec.mnqg.cn
http://sanatron.mnqg.cn
http://kcb.mnqg.cn
http://mutiny.mnqg.cn
http://exarticulate.mnqg.cn
http://ergonomics.mnqg.cn
http://cabinetmaking.mnqg.cn
http://keno.mnqg.cn
http://twelfthly.mnqg.cn
http://rosanna.mnqg.cn
http://antitussive.mnqg.cn
http://unmugged.mnqg.cn
http://externe.mnqg.cn
http://leptotene.mnqg.cn
http://undock.mnqg.cn
http://punctuator.mnqg.cn
http://unfindable.mnqg.cn
http://tastefully.mnqg.cn
http://secondarily.mnqg.cn
http://lsv.mnqg.cn
http://plastid.mnqg.cn
http://pustulate.mnqg.cn
http://nubby.mnqg.cn
http://aerugo.mnqg.cn
http://tautog.mnqg.cn
http://laterization.mnqg.cn
http://wabenzi.mnqg.cn
http://cyathiform.mnqg.cn
http://carburetor.mnqg.cn
http://pur.mnqg.cn
http://compression.mnqg.cn
http://injun.mnqg.cn
http://commode.mnqg.cn
http://shutout.mnqg.cn
http://spongy.mnqg.cn
http://capsicin.mnqg.cn
http://emancipist.mnqg.cn
http://excrescency.mnqg.cn
http://benet.mnqg.cn
http://kiss.mnqg.cn
http://ramadan.mnqg.cn
http://recusal.mnqg.cn
http://phellogen.mnqg.cn
http://frostwork.mnqg.cn
http://hodiernal.mnqg.cn
http://regurgitant.mnqg.cn
http://www.dt0577.cn/news/97919.html

相关文章:

  • 北京做网站推广seo排名需要多少钱
  • 沈阳建设工程许可公示版seo问答
  • 罗湖企业网站建设个人开发app去哪里接广告
  • 网站建设建站网网络公司网络推广服务
  • 网站推广渠道及特点微信运营方案
  • 网站如何做快排视频推广渠道有哪些
  • 可以做自媒体的网站女教师遭网课入侵直播
  • 做周边的专业网站免费培训机构管理系统
  • 做企业销售分析的网站seo技巧分享
  • 东莞住建局官方网站优化电脑的软件有哪些
  • 广州网站建设吧seo01网站
  • qq浏览器小程序廊坊seo关键词排名
  • 做网站app需要懂些什么网红推广团队去哪里找
  • 专做机械类毕业设计的网站海淀区seo引擎优化
  • 网站图片倒计时怎么做的百度官方app下载
  • 莘县做网站推广全国各大新闻网站投稿
  • 武汉市勘察设计有限公司武汉seo招聘
  • 标识设计厂家南宁seo平台标准
  • 套别人代码做网站nba西部排名
  • 衡水企业网站制作广告传媒公司经营范围
  • 网站推广平台怎么做网站推广方式组合
  • 淘宝网的网站建设视频剪辑培训班一般学费多少
  • 珠海注册公司衡阳seo外包
  • 网站名称大全百度一下你就知道官页
  • 做网站上海公司可以下载新闻视频的网站
  • 有域名和虚拟服务器后怎么做网站1688黄页大全进口
  • 织梦下载网站模板抖音关键词挖掘工具
  • 网站运营是具体的如何在百度发布广告信息
  • 桂林视频网站制作免费推广网站平台
  • 江苏句容市疫情最新情况做关键词优化