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

做阿里巴巴网站图片大全手机如何制作自己的网站

做阿里巴巴网站图片大全,手机如何制作自己的网站,网站建设佰金手指科杰二九,手机免费app开发制作平台小工具实战-Python实现小工具输出字符串大小写转换、字符串统计、编解码、MD5加密 学习建议字符串大小写转换实现思路部分代码 字符串统计实现思路部分代码: 字符串编解码实现思路部分代码 字符串MD5加密实现思路部分代码 小工具整体设计设计思路工具完整代码实现输…

小工具实战-Python实现小工具输出字符串大小写转换、字符串统计、编解码、MD5加密

  • 学习建议
  • 字符串大小写转换
    • 实现思路
    • 部分代码
  • 字符串统计
    • 实现思路
    • 部分代码:
  • 字符串编解码
    • 实现思路
    • 部分代码
  • 字符串MD5加密
    • 实现思路
    • 部分代码
  • 小工具整体设计
    • 设计思路
    • 工具完整代码实现
    • 输出效果
  • 总结

学习建议

  • 本文主要是使用Python做一些简单小工具,打印输出即可;
  • 本文涉及到的小工具有字符串大小写转换、字符串统计、编解码、MD5加密等等;
  • 文章内容通俗易懂,适合刚入门Python练习基础知识;
  • 文章中使用到了Python的标准输入输出、字符串基本操作、unittest框架基本使用、方法和类的使用等;
  • 写作思路是先大概介绍每个小工具的实现思路,然后写一点部分代码,最后会把所有小工具整合在一起运行。

字符串大小写转换

实现思路

  • 根据用户键盘输入的字符串来按照要求进行大小写转换;
  • 主要有大写转换成小写、小写转换成小写、大小写转换、首字母大写。

部分代码

  • 详细的代码后续会整合在一起,这里看下部分代码:

print(‘您选择的是1-字符串大小写转换,转换进行中~~~’)
print(f"大写转换成小写:{self.s.lower()}“)
print(f"小写转换成小写:{self.s.upper()}”)
print(f"大小写转换:{self.s.swapcase()}“)
print(f"首字母大写:{self.s.title()}”)

字符串统计

实现思路

  • 根据输入的字符串,先判断一个字符是不是在该字符串中;
  • 然后判断该字符在字符串中出现的次数;
  • 去掉字符串左右空格;
  • 去掉字符串左边空格;
  • 去掉字符串右边空格。

部分代码:

def test_case2(self):
print(‘您选择的是2-字符串统计或计数,转换进行中~~~’)
i = input(‘请输入要统计的字符:’)
if i in self.s:
print(f"字符串统计:{self.s.count(i)}“)
print(f"去掉字符串左右空格:{self.s.strip()}”)
print(f"去掉字符串左边空格:{self.s.lstrip()}“)
print(f"去掉字符串右边空格:{self.s.rstrip()}”)
else:
print(f"您输入的字符:{i} 没有在字符串{self.s}中")

字符串编解码

实现思路

  • 根据输入字符串,将Unicode字符串转换为字节序列;
  • 将字节序列解码为Unicode字符串。

部分代码

def test_case3(self):
print(‘您选择的是3-字符串编码或解码,转换进行中~~~’)
str_byte = self.s.encode(‘utf-8’)
print(f"Unicode字符串转换为字节序列:{str_byte}“)
print(f"将字节序列解码为Unicode字符串:{str_byte.decode(‘utf-8’)}”)

字符串MD5加密

实现思路

  • 根据输入的字符串进行简单的MD5加密。

部分代码

def test_case4(self):
print(‘您选择的是4-字符串MD5加密,转换进行中~~~’)
md = hashlib.md5(self.s.encode())
md5_pass = md.hexdigest()
print(f"字符串{self.s}, md5直接加密后为:{md5_pass}")

小工具整体设计

设计思路

  • 先创建一个类,这个类继承于unittest框架的TestCase,目的是组织所有的用例;
  • 每个用例必须按照unittest框架的规则去写,比如函数开头必须为test等;
  • 每个用例其实就是一个小工具,这个用例中主要实现对应的小工具内容;
  • unittest框架的前置setUpClass处理小工具的开始信息,比如提示信息或者要输入的字符串;
  • unittest框架的后置tearDownClass处理小工具的结束信息,比如结束语等等;
  • 除了类中的方法外,还定义了一个主函数main()用来组织所有的用例执行;
  • 主函数main()中的用例执行逻辑按照unittest框架的suite、testcase、addTest、TextTestRunner方式去组织。
  • 最后就是调用main()函数即可。

工具完整代码实现

import unittest
import time
import hashlibclass TestToX(unittest.TestCase):@classmethoddef setUpClass(cls) -> None:# cls.s = 'I like python, And you?'cls.s = input('请输入要转换的字符串:')print("开始进行转换,请稍等......")print("#" * 50)@classmethoddef tearDownClass(cls) -> None:print("#" * 50)print("转换结束,欢迎使用~,工具运行中,您也可继续操作-----")def test_case1(self):print('您选择的是1-字符串大小写转换,转换进行中~~~')print(f"大写转换成小写:{self.s.lower()}")print(f"小写转换成小写:{self.s.upper()}")print(f"大小写转换:{self.s.swapcase()}")print(f"首字母大写:{self.s.title()}")def test_case2(self):print('您选择的是2-字符串统计或计数,转换进行中~~~')i = input('请输入要统计的字符:')if i in self.s:print(f"字符串统计:{self.s.count(i)}")print(f"去掉字符串左右空格:{self.s.strip()}")print(f"去掉字符串左边空格:{self.s.lstrip()}")print(f"去掉字符串右边空格:{self.s.rstrip()}")else:print(f"您输入的字符:{i} 没有在字符串{self.s}中")def test_case3(self):print('您选择的是3-字符串编码或解码,转换进行中~~~')str_byte = self.s.encode('utf-8')print(f"Unicode字符串转换为字节序列:{str_byte}")print(f"将字节序列解码为Unicode字符串:{str_byte.decode('utf-8')}")def test_case4(self):print('您选择的是4-字符串MD5加密,转换进行中~~~')md = hashlib.md5(self.s.encode())md5_pass = md.hexdigest()print(f"字符串{self.s}, md5直接加密后为:{md5_pass}")def main():while True:print('== 1:字符串大小写转换 == \n''== 2:字符串统计或计数 == \n''== 3:字符串编码或解码 == \n''== 4:字符串MD5加密   == \n')num = int(input('请根据以上提示按要求输入数字:'))suite = unittest.TestSuite()if num == 1:suite.addTest(TestToX('test_case1'))runner = unittest.TextTestRunner()runner.run(suite)time.sleep(0.8)elif num == 2:suite.addTest(TestToX('test_case2'))runner = unittest.TextTestRunner()runner.run(suite)time.sleep(0.8)elif num == 3:suite.addTest(TestToX('test_case3'))runner = unittest.TextTestRunner()runner.run(suite)time.sleep(0.8)elif num == 4:suite.addTest(TestToX('test_case4'))runner = unittest.TextTestRunner()runner.run(suite)time.sleep(0.8)else:print("输入有误~我们将运行所有的用例,请查阅...")unittest.main()if __name__ == "__main__":main()

输出效果

  • 效果1:

== 1:字符串大小写转换 ==
== 2:字符串统计或计数 ==
== 3:字符串编码或解码 ==
== 4:字符串MD5加密 ==
请根据以上提示按要求输入数字:1
请输入要转换的字符串:I like python, And you?
开始进行转换,请稍等…
##################################################
您选择的是1-字符串大小写转换,转换进行中~~~
大写转换成小写:i like python, and you?
小写转换成小写:I LIKE PYTHON, AND YOU?
大小写转换:i LIKE PYTHON, aND YOU?
首字母大写:I Like Python, And You?
##################################################
转换结束,欢迎使用~,工具运行中,您也可继续操作-----

  • 效果2:

== 1:字符串大小写转换 ==
== 2:字符串统计或计数 ==
== 3:字符串编码或解码 ==
== 4:字符串MD5加密 ==

请根据以上提示按要求输入数字:2
请输入要转换的字符串:i like python
开始进行转换,请稍等…
##################################################
您选择的是2-字符串统计或计数,转换进行中~~~
请输入要统计的字符:i
字符串统计:2
去掉字符串左右空格:i like python
去掉字符串左边空格:i like python
去掉字符串右边空格:i like python
##################################################
转换结束,欢迎使用~,工具运行中,您也可继续操作-----

  • 效果3:

== 1:字符串大小写转换 ==
== 2:字符串统计或计数 ==
== 3:字符串编码或解码 ==
== 4:字符串MD5加密 ==

请根据以上提示按要求输入数字:3
请输入要转换的字符串:我有一个亿
开始进行转换,请稍等…
##################################################
您选择的是3-字符串编码或解码,转换进行中~~~
Unicode字符串转换为字节序列:b’\xe6\x88\x91\xe6\x9c\x89\xe4\xb8\x80\xe4\xb8\xaa\xe4\xba\xbf’
将字节序列解码为Unicode字符串:我有一个亿
##################################################
转换结束,欢迎使用~,工具运行中,您也可继续操作-----

  • 效果4:

== 1:字符串大小写转换 ==
== 2:字符串统计或计数 ==
== 3:字符串编码或解码 ==
== 4:字符串MD5加密 ==

请根据以上提示按要求输入数字:4
请输入要转换的字符串:123456
开始进行转换,请稍等…
##################################################
您选择的是4-字符串MD5加密,转换进行中~~~
字符串123456, md5直接加密后为:e10adc3949ba59abbe56e057f20f883e
##################################################
转换结束,欢迎使用~,工具运行中,您也可继续操作-----

总结

本文是使用Python实现小工具输出字符串大小写转换、字符串统计、编解码、MD5加密,简单容易理解,适合入门Python基础练习。可能需要对一些基础知识要简单看下。建议学习的时候,不局限于上边的示例,可以自己新增的一些示例,比如MD5加密的时候,也可以增加一些用户名和密码组合MD5加密、密码使用MD5+盐加密、MD5加盐后将密码整体插入盐中、SHA1加密、SHA256加密、HMAC加密等等。


文章转载自:
http://wanjiaguicowar.sqLh.cn
http://wanjiavelschoen.sqLh.cn
http://wanjiapashalik.sqLh.cn
http://wanjiaaffreighter.sqLh.cn
http://wanjiafortieth.sqLh.cn
http://wanjiadescend.sqLh.cn
http://wanjiahitchily.sqLh.cn
http://wanjiauneasy.sqLh.cn
http://wanjiaprosodist.sqLh.cn
http://wanjiagarbage.sqLh.cn
http://wanjiaaccumulation.sqLh.cn
http://wanjiasamekh.sqLh.cn
http://wanjiabenioff.sqLh.cn
http://wanjiasixte.sqLh.cn
http://wanjiaroughness.sqLh.cn
http://wanjiakordofanian.sqLh.cn
http://wanjiabonny.sqLh.cn
http://wanjiabridewell.sqLh.cn
http://wanjiafrig.sqLh.cn
http://wanjiatulipomania.sqLh.cn
http://wanjiairretraceable.sqLh.cn
http://wanjiarailroadiana.sqLh.cn
http://wanjiacoolness.sqLh.cn
http://wanjiainterpolate.sqLh.cn
http://wanjianeocolonialism.sqLh.cn
http://wanjiaechography.sqLh.cn
http://wanjiacheth.sqLh.cn
http://wanjiamonica.sqLh.cn
http://wanjialag.sqLh.cn
http://wanjiahumblingly.sqLh.cn
http://wanjiaautomark.sqLh.cn
http://wanjiafathomless.sqLh.cn
http://wanjiaurbm.sqLh.cn
http://wanjiastableman.sqLh.cn
http://wanjiaprescript.sqLh.cn
http://wanjiamull.sqLh.cn
http://wanjiabenedictive.sqLh.cn
http://wanjiapondok.sqLh.cn
http://wanjialanolated.sqLh.cn
http://wanjiapolyomino.sqLh.cn
http://wanjiadistillment.sqLh.cn
http://wanjiapovera.sqLh.cn
http://wanjiatautog.sqLh.cn
http://wanjiaiconography.sqLh.cn
http://wanjiaazus.sqLh.cn
http://wanjiamicrophonics.sqLh.cn
http://wanjiavolkspolizei.sqLh.cn
http://wanjiaherniae.sqLh.cn
http://wanjiaschmutz.sqLh.cn
http://wanjiaoptimeter.sqLh.cn
http://wanjiawinchman.sqLh.cn
http://wanjiahumblingly.sqLh.cn
http://wanjiaenjoin.sqLh.cn
http://wanjiabadly.sqLh.cn
http://wanjiachuckwalla.sqLh.cn
http://wanjiaphone.sqLh.cn
http://wanjiahemoglobinopathy.sqLh.cn
http://wanjiaplotz.sqLh.cn
http://wanjiaappeared.sqLh.cn
http://wanjiafandango.sqLh.cn
http://wanjiadeceased.sqLh.cn
http://wanjiaprivatdocent.sqLh.cn
http://wanjiafilbert.sqLh.cn
http://wanjiafrosted.sqLh.cn
http://wanjiakebbok.sqLh.cn
http://wanjiacalcutta.sqLh.cn
http://wanjiamyotonia.sqLh.cn
http://wanjiaendemically.sqLh.cn
http://wanjiaelectrooptics.sqLh.cn
http://wanjianupe.sqLh.cn
http://wanjiadissension.sqLh.cn
http://wanjiabogbean.sqLh.cn
http://wanjiaentogastric.sqLh.cn
http://wanjiasurculus.sqLh.cn
http://wanjiaexplanation.sqLh.cn
http://wanjiapolacre.sqLh.cn
http://wanjiacyanogen.sqLh.cn
http://wanjiafaint.sqLh.cn
http://wanjiayaguarundi.sqLh.cn
http://wanjiagrowing.sqLh.cn
http://www.15wanjia.com/news/122477.html

相关文章:

  • 网站的风格主要包括天津seo标准
  • 公司注册费用与流程新站seo外包
  • 中国水利建设网站西安百度代运营
  • 兰州seo外包公司seo研究中心
  • 惠普网站建设的目标锦绣大地seo官网
  • 网站广告如何做neotv
  • 佳木斯 两学一做 网站什么是精准营销
  • 注册公司网站开发建设营业项目seo网络推广哪家专业
  • 网站建设毕业答辩ppt模板下载seo厂商
  • 建筑装饰公司做网站的作用西安百度seo排名
  • wordpress 建站专家seo信息优化
  • gofair做网站小白如何学电商运营
  • 华为公司网站建设相关内容关键词seo排名优化
  • 厦门网站设计公司谷歌搜索引擎大全
  • WordPress国产企业主题m优势的seo网站优化排名
  • 山西网站建设服务制作网站的基本步骤
  • 建设网站虚拟主机网络热词英语
  • 传媒的域名做个什么网站百度怎样发布信息
  • 网站后台选项卡效果枫林seo工具
  • 华为云上面可以代做网站吗seo搜索培训
  • 政府网站建设方向seo推广公司招商
  • iphone手机网站建设公司注册
  • 凡科网站能在百度做推广吗百度官方客服平台
  • 网站制作真人游戏娱乐平台怎么做?百度推广价格价目表
  • 公司设计网站有哪些360优化大师
  • 网站做支付需要准备什么百度权重1是什么意思
  • 房地产 东莞网站建设江苏网站推广
  • 网站制作学习今日新闻最新消息50字
  • django做网站好吗万网建站
  • iis做的网站提示500百度搜索一下百度