I tried to run this code with input "AC039"
code = input("Enter code: ").upper()
if code[0] != ('N' or 'A' or 'C' ):
print("The first character must be N, A or C")
else:
print("Pass!")
It gave me the output error result:
The first character must be N, A or C
However, if I input "AC039" into the below code using 'not in',
code = input("Enter code: ").upper()
if code[0] not in ["N", "A", "C"]:
print("The first character must be N, A or C")
else:
print("Pass!")
The resulting output is:
print("Pass!")
Why doesn't "!=" work for the first set of code, since both code[0] and 'A' are string types?
I ran a check using type function on code[0] and it returned string type.
code = input("Enter code: ").upper()
print(type(code[0]))
print(type('A'))
returns:
<class 'str'>
<class 'str'>