String Validators

Sort by

recency

|

1935 Discussions

|

  • + 0 comments

    this question taught me a lot.i didnt even know that python has a concept of for-else,i thought that we can use else with a preceding if but there's more to it. basically in a for-else,the else bloock is exceuted if the loop ran completely and was not interupted by a break statement.

        s = input()
        for i in s:
            if i.isalnum():
                print("True")
                break
        else:        #for else,else executes only when loop isnt broken
            print("False")
        for i in s:
            if i.isalpha():
                print("True")
                break
        else:
            print("False")
        for i in s:
            if i.isdigit():
                print("True")
                break
        else:
            print("False")
        for i in s:
            if i.islower():
                print("True")
                break
        else:
            print("False")
        for i in s:
            if i.isupper():
                print("True")
                break
        else:
            print("False")
        
             
    
    
    
  • + 0 comments
    if __name__ == '__main__':
        s = input()
        operations = ["isalnum","isalpha","isdigit","islower","isupper"]
        for i in operations:
            print(any(getattr(c,i)() for c in s))
    
  • + 0 comments

    s = input()

    has_alnum = has_alpha = has_digit = has_lower = has_upper = False

    for c in s: if c.isalnum(): has_alnum = True

    if c.isalpha():
        has_alpha = True
    
    if c.isdigit():
        has_digit = True
    
    if c.islower():
        has_lower = True
    
    if c.isupper():
        has_upper = True
    

    print(has_alnum) print(has_alpha) print(has_digit) print(has_lower) print(has_upper)

  • + 0 comments
    import re
    
    if __name__ == '__main__':
        s = input()
        
        print(bool(re.search(r'[a-zA-Z0-9]', s)))  
        print(bool(re.search(r'[a-zA-Z]', s)))     
        print(bool(re.search(r'[0-9]', s)))        
        print(bool(re.search(r'[a-z]', s)))       ercase
        print(bool(re.search(r'[A-Z]', s)))        # uppercase
    
  • + 1 comment
    if __name__ == '__main__':
        s = input()
        
        list_of_operations= ['isalnum', 'isalpha', 'isdigit', 'islower', 'isupper']
        
        for operation in list_of_operations:
        
            operation_done= any([getattr(letter, operation)() for letter in s])
            print(operation_done)