后端开发|Python教程
python
后端开发-Python教程
需求
html 源码手机版,ubuntu系统界面截图,双击tomcat9弹出乱码,爬虫被限流,php5.6.40下载,seo引流机器lzw
随机生成定长的大写字母和数字组合。
ecstore2.3 源码,vscode远程连接不上,ubuntu 建立图标,tomcat关闭提示线程,淘宝封爬虫,php id 加密,济南seo推广哪家值得信赖,运行网站源码,中央空调设备系统类网站织梦模板lzw
ddnspod动态域名解析软件 源码,32位乌班图安装vscode,缺少依赖ubuntu,tomcat如何增加内存,java爬虫发布,php自学 兄弟连,北京丰台百度seo,企业展示网站模板免费下载lzw
实现
#!/usr/bin/env python# -*- coding:utf-8 -*-import randomdef getRandomSet(bits): num_set = [chr(i) for i in range(48,58)] char_set = [chr(i) for i in range(65,90)] total_set = num_set + char_set value_set = "".join(random.sample(total_set, bits)) return value_setif __name__ == \__main__ : strings = getRandomSet(26) print(strings)
分析
1、首先使用chr()函数,生成大写字母和数字两个列表
2、合并两个列表
3、使用random模块的sample采样函数,随机采集指定位数的字符。
4、random采样的结果是列表,还需要转换成str类型,使用str的join函数即可。