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("%%%"))]
              
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值