python - 检查字符串是否只包含一些值,而不包含其他值

标签 python

print("Hello, welcome to password strength. Test how strong your password is todai!")
password = input("Well enter a password why don't you... ")
print("So your password is", password)
print("Well ok, let's see what i can understand from this...")

if len(password) < 6:   
    print("Your password is too short")    
else:    
    print("Your password is of a good length")    

if password == password.upper():    
    print("Your password has too many uppercase letters")
else:    
    print("Your password has 0 or a couple upper case letters, please consider making your password remember-able.")

if password == password.lower():    
    print("Your password needs a upper case letter case letters")
else:    
    print("Your password has a suitable amount of lowercase vs upper case letters")

if password == 

这是我想问密码是否只包含数字的地方,但我不知道该怎么做,我已经尝试过使用 ands 和 ors,但失败得很惨。

最佳答案

使用isdigit()

>>> "abcd123".isdigit()
False

>>> "123".isdigit()
True

关于python - 检查字符串是否只包含一些值,而不包含其他值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27058723/

相关文章:

Python turtle 图

python - 如何在 Sklearn 中为 Matern 内核指定 nu=infinity?

python - 如何根据索引值匹配值?

python - Multiindex pandas groupby + aggregate,保留全索引

python - 在 python 中自定义 __delattr__

python - 捕获在 python 中运行的 bash 代码的输出

Python 的 String 类的 count() 方法

python - 是否可以在 python 中使用 http.server 显示目录中的文件大小?

python - 如何在python中使用套接字而无需等待

python - 获取特定 Outlook 文件夹/收件箱中的类别列表