一、简介
生成随机密码,英文大小写和数字的组合。
二、使用方法
调用GetCode
方法,num
参数设置密码位数。
import string
from random import choices
def GetCode(num:int) ->str:
us_lower = [cell for cell in string.ascii_lowercase]
us_upper = [cell for cell in string.ascii_uppercase]
num = [cell for cell in string.digits]
return "".join([choices(us_lower + us_upper + num)[0] for index in range(num)])
if __name__ == "__main__":
code = GetCode(4)
print(code)