def is_valid_password(password):
    if len(password) < 6:
        return False
    has_upper = False
    has_lower = False
    has_digit = False
    for char in password:
        if char.isupper():
            has_upper = True
        if char.islower():
            has_lower = True
        if char.isdigit():
            has_digit = True
    return has_upper and has_lower and has_digit

使用示例:

print(is_valid_password("Abc123"))  # True
print(is_valid_password("123456"))  # False
print(is_valid_password("ABCDEF"))  # False
print(is_valid_password("aBc123"))  # True
print(is_valid_password("Abc"))     # False
``
用python写一个函数判断输入的字符串是由大写字母、小写字母和数字组成而且至少6位而且至少含有一个大写字母而且至少含有一个小写字母而且至少含有一个数字。

原文地址: https://www.cveoy.top/t/topic/fDN3 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录