标签:shuff else hello def sample and shu 不包含 for
print(random.randint(1,8)) #包含8
print(random.choice(‘hello‘))
print(random.choice([‘123‘,4,[1,2]]))
print(random.shuffle(‘hello‘))
print(random.sample([‘123‘,4,[1,2]],2)) #取2个随机值
print(random.randrange(1,8)) #不包含8
验证码生成器
import random
def v_code():
code = ‘‘
for i in range(5):
if i == random.randrange(0,2):
add = random.randrange(10)
else:
add = chr(random.randrange(65,90))
code += str(add)
print(code)
v_code()
精简:
import random
def v_code():
code = ‘‘
for i in range(5):
add =random.choice([random.randrange(10),chr(random.randrange(65,90))])
code += str(add)
print(code)
v_code()
标签:shuff else hello def sample and shu 不包含 for
原文地址:http://www.cnblogs.com/y-m-f/p/7803657.html