password = "VerySecurePassw0rd"
if "%" in password:
print( "Your Password has a special character in it!")
if "%" not in password:
print ("Your Password does not have a special character in it!")
编辑:
或者你可以用上面的“else”
如果不使用循环,我不确定您是否可以使用“elif”,但它不是很有效
password = "VerySecurePassw0rd"
if "%" in password:
print ("Your Password has a special character in it!")
elif "$" in password:
print( "Your Password has a special character in it!")
elif "#" in password:
print ("Your Password has a special character in it!")
你也可以试试这个:
if "%" and "$" in password:
print("Your Password has a 2 special characters in it!")
import string
all_normal_characters = string.ascii_letters + string.digits
def is_special(character):
return character not in all_normal_characters
special_characters = [character for character in password if is_special(character)]
你必须把它放入一个for循环来检查特殊字符,我认为你需要列出一个包含所有字符的列表,然后像这样测试它,但这是你需要的基本代码!把打印位换成你需要做的任何事!
编辑:
或者你可以用上面的“else”
如果不使用循环,我不确定您是否可以使用“elif”,但它不是很有效
你也可以试试这个:
我认为那应该管用
你可以用正则表达式!
快乐编码!
希望有帮助!
如您所述,您不想使用循环,而且可能从未使用过regex,那么列表理解如何?
让我知道这是否有效,或者如果你需要更多的帮助!
相关问题 更多 >
编程相关推荐