>>> print(random.random()) #random() -> x in the interval [0, 1) 0.9276252205739922 >>> print(random.randint(1,2)) #随机取1-2之间的整数 1
2.随机码
>>> import random >>> checkcode = ‘‘ >>> for i in range(4): ... current = random.randrange(0,4) ... if current != i: ... temp = chr(random.randint(65,90)) ... else: ... temp = random.randint(0,9) ... checkcode += str(temp) ... >>> print(checkcode) UFWZ
本文出自 “AMY” 博客,请务必保留此出处http://amy2015.blog.51cto.com/11407620/1771892
原文地址:http://amy2015.blog.51cto.com/11407620/1771892