【发布时间】:2015-07-01 09:35:09
【问题描述】:
我正在尝试查看如何查看用户输入中是否有数字。我尝试使用.isdigit(),但只有在它只是一个数字时才有效。我试图将其添加到密码检查器中。我也试过.isalpha(),但没用。我做错了什么,我需要添加或更改什么?
这就是我所拥有的
password = input('Please type a password ')
str = password
if str.isdigit() == True:
print('password has a number and letters!')
else:
print('You must include a number!')`
【问题讨论】:
-
@vinash-raj 回答了您的问题,但您确实应该为您的用例考虑 github.com/dropbox/zxcvbn(或 Python 版本的 github.com/dropbox/python-zxcvbn)
标签: python string input numbers python-3.4