【Python小随笔】验证码函数

def random_code_six():
    """
        :return 58yWNl
    """
    str = ""
    for i in range(6):
        code = random.randrange(3)
        if code == 0:
            ch = chr(random.randrange(ord("A"), ord("Z") + 1))
            str += ch
        elif code == 1:
            ch = chr(random.randrange(ord("a"), ord("z") + 1))
            str += ch
        elif code == 2:
            ch = chr(random.randrange(ord("0"), ord("9") + 1))
            str += ch
    return str

 

posted @ 2022-05-25 14:04  PythonNew_Mr.Wang  Views(58)  Comments(0)    收藏  举报