一.random模块
1 >>> import random
2 >>>random.choice("abcdefg") # 产生一个随机字母,参数也可以是一个列表
3 >>>s = "abcdefghight"
4 >>>random.sample(s, 3) # 从数据s中随机取出3个值
5 >>>random.randint(1, 100) # 从1到100中随机取出一个数,包含1和100。
二.string模块
1 >>> import string
2 >>> string.ascii_letters # 全部的大小写字母
3 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
4 >>> string.ascii_uppercase # 所有的大写字母
5 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
6 >>> string.ascii_lowercase # 所有的小写字母
7 'abcdefghijklmnopqrstuvwxyz'
8 >>> string.punctuation # 所有的特殊字符
9 '!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~'
10 >>> string.digits # 所有的数字
11 '0123456789'