(Oct-31-2019, 06:37 AM)ndc85430 Wrote: You then compare the return value of answer.lower() with True and the expression answer.lower() != True will always evaluate to True because answer.lower() returns a string and values of different types (string and bool here) will never be equal.
Actually the second part of your explanation (the one I have quoted) is not correct. The first part about true-testing is correct.
"y" or "n"
will return "y"
(i.e. first element that is considered to be True
). So if you have False or None or [] or 'spam'
it will return 'spam'
And
'y' and 'n'
will return 'n'
- i.e. the last element considered to be True
That is why
answer.lower() != ("y" or "n"):
is same as answer.lower() != "y":
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs