【发布时间】:2020-12-26 01:42:17
【问题描述】:
我正在编写具有多个属性的密码分析器,其中一个是用户的密码不能包含特殊字符 (@#$%^&*),! 除外(感叹号)和 _(下划线)。我为此目的使用了.isalnum() 方法,但我无法找到一种方法,因此当 ! 或 _ 与任何一起使用时它不会返回 True其他特殊字符(例如:Python$ 返回 False,但 Python_ 返回 True)。
这是我的代码:
password = input('Enter a password: ')
if not password.isalnum():
if '_' in password or '!' in password:
pass
else:
print('Your password must not include any special characters or symbols!')
【问题讨论】:
标签: python