randam模块 (随机选择)
import random print (random.random()) print (random.randint(1,2)) print (random.randrange(1,10))
import random,string str_1 = string.ascii_letters+string.digits temp = ''.join(random.sample(str_1,6)) print (temp) checkcode = '' for i in range(6): current = random.randrange(0,6) if current != i: temp = chr(random.randint(65,90)) else: temp = random.randint(0,9) checkcode += str(temp) print (checkcode)