标签:ber pre dom amp += choice pytho port 选择
print(random.random()) # (0,1) 随机小数 0到1
print(random.randint(3,5))# [3,4,5] 取整
print(random.randrange(3,5))# [3,5) 取整
print(random.choice([111,222,333,‘aaa‘])) # 随机选择一个
print(random.sample([111,222,‘aaa‘,2],2)) # 随机选择2个搭配,后面的参数2可以改,设置随机抽取几个值
print(random.uniform(1,3))# 指定范围 1到3之间的小数
print(random.shuffle([1,2,3,4,]))#洗牌功能,打乱
chr() 把ascii码转换成 字符
ord() 把字符转换为ascii码
print(ord(‘A‘)) # 65 # ord这个功能会参照ASCII码表把大写字母转成数字
print(ord(‘Z‘)) # 90
print(chr(65)) # A # chr这个功能会参照ASCII码表把数字转成大写字母
import random
def suiji(num=6):
res = ‘‘
for i in range(num):
number = str(random.randint(0, 9))
ipa = chr(random.randint(65, 90))
res += random.choice([number, ipa])
return res
print(suiji())
标签:ber pre dom amp += choice pytho port 选择
原文地址:https://www.cnblogs.com/BaiJiaZhengMing/p/14612215.html