In python, how do you check if a string has both uppercase and lowercase letters

后端 未结 4 622
独厮守ぢ
独厮守ぢ 2021-01-14 17:34

I\'ve looked at the other post similar to my question, Password check- Python 3, except my question involves checking if the password contains both uppercase and lower case

4条回答
  •  不思量自难忘°
    2021-01-14 18:02

    Your question is simple to answer. You are returning things of the form return('steps' == True) which is always going to return false. So just replace those with return True or return False.

    Assuming you fix the above, your looping is also buggy. You only want to return false after you have looped through the entire string. Consider the password: ABCd. This contains a lowercase character but your check lowercase method would return false because the first letter is uppercase. You want to look through every character in password and if none of those are lowercase, then return false.

    If you want a neater way to do it, cdlane's answer is a nice pythonic way.

提交回复
热议问题