标签:2.4 def pytho ice author shuffle style shuf dom
__author__ = "jocket2333"
import random
print(random.random())
# (0, 1)------ float
print(random.randint(1, 3))
# [1, 3]
print(random.randrange(1, 3))
# [1, 3)
print(random.choice([1, ‘23‘,[4, 5]]))
# 23
print(random.sample([1, ‘23‘, [4,5]], 2))
# [[4, 5], ‘23‘]
print(random.uniform(1, 3))
# 2.4493238844781944
# item = [1, 3, 5, 7,9]
# random.shuffle(item)
# 任意排序
# print(item)
# [7, 3, 1, 5, 9]
#--------------------------------------------------------------
项目:验证码
__author__ = ‘jocket2333‘
import random
def v_code():
code = ‘‘
for i in range(5):
num = random.randint(0,9)
alf = chr(random.randint(65, 90))
add = random.choice([num, alf])
code += str(add)
return code
print(v_code())
标签:2.4 def pytho ice author shuffle style shuf dom
原文地址:https://www.cnblogs.com/qianjunye/p/10357398.html