I'm trying to make sure that a word variable doesn't contain characters from a forbidden characters list. This all seems to work fine until I enter more than one character however.
For example, code here returns that there are special characters in the string variable as expected.
specialCharacters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!"#$%&\'()*+,-/:;<=>?@[\\]^_`{|}~ \t\n\r\x0b\x0c'
string = "a"
if string in specialCharacters:
print("There are special characters!")
else:
print("No special characters found!")
# This prints "There are special characters!"
However, when the string contains two of the same characters from the specialCharacters list, it returns that there are no special characters when it in fact does. Why isn't Python recognising the special characters when there are simply more of it?
specialCharacters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!"#$%&\'()*+,-/:;<=>?@[\\]^_`{|}~ \t\n\r\x0b\x0c'
string = "aa"
if string in specialCharacters:
print("There are special characters!")
else:
print("No special characters found!")
# This prints "No special characters found!"