def is_valid_string(s):
    has_upper = False
    has_lower = False
    has_digit = False
    for c in s:
        if c.isupper():
            has_upper = True
        elif c.islower():
            has_lower = True
        elif c.isdigit():
            has_digit = True
    return has_upper and has_lower and has_digit

# test
print(is_valid_string('Abc123')) # True
print(is_valid_string('ABC123')) # False
print(is_valid_string('abc123')) # False
print(is_valid_string('Abc')) # False
print(is_valid_string('123')) # False
Python 函数判断字符串是否包含大写字母、小写字母和数字

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

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