random:随机数
import random
print(random.random())#(0,1)----float 大于0且小于1之间的小数
print(random.randint(1,3)) #[1,3] 大于等于1且小于等于3之间的整数
print(random.randrange(1,3)) #[1,3) 大于等于1且小于3之间的整数
print(random.choice([1,'23',[4,5]])) #1或者23或者[4,5]任意选1个
print(random.sample([1,'23',[4,5]],2)) #列表元素任意2个组合
print(random.uniform(1,3)) #大于1小于3的小数,如1.927109612082716
item=[1,3,5,7,9]
random.shuffle(item) #打乱item的顺序,相当于"洗牌"
print(item)案例:生成随机6位验证码(数字、大小写字母)
def make_code(n): res='' for i in range(n): s1=chr(random.randint(65,90)) #大写字母 s2=chr(random.randint(97,122)) #小写字母 s3=str(random.randint(0,9)) res+=random.choice([s1,s2,s3]) return resprint(make_code(6))
转载于:https://www.cnblogs.com/zhangdajin/p/11140851.html
相关资源:DirectX修复工具V4.0增强版