By pushing the python code generation / verification code

By pushing the python code generation / verification code

Interpolation code / codes generally consist of uppercase and lowercase letters and numbers of these three characters is
thus introduced into the first alphanumeric library

import random     #导入数字的库
import string     #导入字符的库

print(string.ascii_letters)
print(string.ascii_uppercase)
print(string.ascii_lowercase)
print(string.digits)

Output:

abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ
ABCDEFGHIJKLMNOPQRSTUVWXYZ
abcdefghijklmnopqrstuvwxyz
0123456789

4 randomly generated interpolation code letters and numbers, scrambled

import random
import string

code_str = string.ascii_letters + string.digits
print(code_str)

def gen_code(len=4):
    # code = ''
    # for i in range(len):
    #     new_s = random.choice(code_str)
    #     code += new_s
    # return code
    return ''.join(random.sample(code_str,len))

print([gen_code(4) for i in range(10)])

Output:

abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789
['pNAO', 'rQM2', 'UHhe', 'ndbE', 'bNz1', '0U4k', '9n4p', 'oF3J', 'h2wr', 'g8ZH']

6 interpolation randomly generated code, the letters and numbers, scrambled

import random
import string

code_str = string.ascii_letters + string.digits
print(code_str)
# print(random.sample(code_str,4))
def gen_code(len=4):
    # code = ''
    # for i in range(len):
    #     new_s = random.choice(code_str)
    #     code += new_s
    # return code
    return ''.join(random.sample(code_str,len))

print([gen_code(6) for i in range(10)])

Output:

abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789
['rZuEKz', 'r8jYxC', 'VyeIrd', 'M564Km', 'kpRg1s', 'VeN79v', 'HLMQw4', 'Kvrecb', 'n1qwH3', '83TaGJ']
Published 60 original articles · won praise 6 · views 1344

Guess you like

Origin blog.csdn.net/weixin_45775963/article/details/103716840