random模块笔记-DStar-Note

At the begining stage of learning pyhton in English
any grammer or spelling mistake might happen,please just write in comment ,I will rewrite latter

import random
#random int
print (random.randint(1,50))

#random even numbers between 0~100
print (random.randrange(0,101,2))

#random float 
print (random.random()) #defult(0,1)
print (random.uniform(1,10))

#random string
print (random.choice("SHIFJFIHDISJFHIS$^*#$%^&*(")

#random string from specific strings with specific numer
print (random.sample("hdiyaiferiwojkgosfr","8")

import string
#random string from a-zA-Z0-9 with specific numbers
r_str = ''.join(random.sample(srting.ascii_letters +string.digits,8)
print (r_str)

#choice random str
print random.choice(['apple','pencil','orange'])

#shuffle
num = [1,3,5,7,]
print random.shuffle(num)

《Hardway》 ex41

class_name = [w.capitalize() for w in
              random.sample(WORDS,snippet.count("%%%"))]
              
已标记关键词 清除标记
©️2020 CSDN 皮肤主题: 数字20 设计师:CSDN官方博客 返回首页