import random import string print(random.randint(1,100)) #产生1——100的随机整数 print(random.choice(["q",'mpp',1,100,999])) #随机选择一个,传list或字符串 print(random.sample(["q",'mpp',1,100,999],2)) #随机取N个元素,返回的是哥哥list print(random.uniform(1,10)) #随机去个浮点数 l = ["q",'mpp',1,100,999] random.shuffle(l)#洗牌,打乱顺序,只能传list print(l) print(string.digits) print(string.ascii_lowercase) print(string.ascii_uppercase) print(string.ascii_letters) print(string.punctuation)
运行结果
6 q [1, 999] 8.646511513588939 [999, 100, 'mpp', 'q', 1] 0123456789 abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ !"#$%&'()*+,-./:;<=>?@[\]^_`{|}~