In python, how do you check if a string has both uppercase and lowercase letters
<p>I've looked at the other post similar to my question, <a href="http://stackoverflow.com/questions/36380351/password-check-python-3">Password check- Python 3</a>, except my question involves checking if the password contains both uppercase and lower case questions. My code is the following, but when executed it fails to recognize that both lower and upper case letters are in the password, it only recognizes one type. How would I get it to recognize both types? Also is there an easier way to have the code check if all of those values occur without having to make functions for each individual step?</p>

<pre><code>def Get_Password():
    return input("Enter your desired password: ")

def Count_Digits(password):
    return sum(character.isdigit() for character in password)

def Valid_password_length(password):
    if len(password) &gt;= 10:
        return ('step1' == True)
    else:
        return ('step1' == False, print("Invalid password: too short"))

def Valid_password_characters(password):
    if password.isalnum():
        return ('step2' == True)
    else:
        return ('step2' == False, print("Invalid password: illegal character detected"))

def Valid_password_numdigit(password):
    if Count_Digits(password) &gt;= 2:
        return ('step3' == True)
    else:
        return ('step3' == False, print("Invalid password: Must have at least 2 digits"))

def Valid_password_lowercase(password):
    for i in (password):
        if i.islower() == True:
            return ('step4' == True)
        else:
            return ('step4' == False, print("Invalid password: No lowercase characters detected"))

def Valid_password_uppercase(password):
    for i in (password):
        if i.isupper() == True:
            return ('step5' == True)
        else:
            return ('step5' == False, print("Invalid password: No uppercase characters detected"))

def password_checker():
    password = Get_Password()
    Valid_password_length(password)
    Valid_password_characters(password)
    Valid_password_numdigit(password)
    Valid_password_lowercase(password)
    Valid_password_uppercase(password)

    if 'step1' and 'step2' and 'step3' and 'step4' and 'step5' == True:
        print("Congratulations! This password is valid")

password_checker()
</code></pre>

<p>You could use regular expression : </p>

<p>i.e. : </p>

<pre><code>def Valid_mixed_password(password):
    lower = re.compile(r'.*[a-z]+') # Compile to match lowercase
    upper = re.compile(r'.*[A-Z]+') # Compile to match uppercase
    if lower.match(password) and upper.match(password): # if the password contains both (lowercase and uppercase letters) then return True
        return True
    else: # Else, the password does not contains uppercase and lowercase letters then return False
        return False

&gt;&gt;&gt; print Valid_mixed_password("hello")
False
&gt;&gt;&gt; print Valid_mixed_password("HELLO")
False
&gt;&gt;&gt; print Valid_mixed_password("HellO")
True
&gt;&gt;&gt; print Valid_mixed_password("heLLo")
True
</code></pre>

<p>Hope it helps. </p>

python string