用户在创建密码时使用特殊字符

The user to use special characters when creating a password

我希望用户在创建密码时使用特殊字符。(至少 1 个) 示例:

special_character= list(string.punctuation)
password=input("enter password:")
if any(i not in password for i in special_character):
    print("You should add a special character for creating strong password!")

会这样但是不行。你能帮助我吗?谢谢

只需使用 all(...),或者使用 not any(...) 但在列表理解中不使用 not(这样更好,因为 not 得到 运行总体上减少了次数,使其效率略有提高)。这就是代码的样子:

special_characters = list(string.punctuation)
password = input("Enter password: ")
if not any(i in password for i in special_characters):
    print("You should add a special character for creating strong password!")