String Validators

  • + 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")