生成隨機密碼,英文大小寫和數字的組合。
調用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)