from random import choice import string all_chs = string.ascii_letters + string.digits def gen_pass(n=8): #默认是循环8次,也就是生成8位密码 result = '' for i in range(n): ch = choice(all_chs) result +=ch return result if __name__ == '__main__': print(gen_pass()) print(gen_pass(4)) #生成4位的密码 print(gen_pass(10)) #生成10位的密码 # 解释 # >>> import string # >>> string.ascii_letters # 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' # >>> string.digits # '0123456789' # 测试 # [root@zhuji pyrhon百例]# python3 37生成密码验证密码.py # FsOHGZ87 # BNhA # Q0wO0ANAzg
python-生成密码(37)
最新推荐文章于 2021-05-31 16:32:14 发布