+ 3
What happens when I compare Boolean value with string value using Boolean operator?
True and 'spam' == spam? I searched for Boolean operator and what I got was: 'and is Boolean operator. This compares the two value and evaluates to single Boolean value.' First, I wondered why it doesn't evaluate to single Boolean value. So I thought maybe 'True and' doesn't affect anything. But when I tried True or 'spam', It turned out to True and I was wrong! I searched it on web but there was no Python. Here's more thing I experimented. https://code.sololearn.com/c7dHDGfw1ywZ/?ref=app
3 odpowiedzi
+ 2
x AND y (if x is false, returns x, otherwise y)
x OR y (if x is true, returns x, otherwise y)
Here you can find more info:
https://docs.python.org/2/reference/expressions.html#boolean-operations
Note that:
bool("") returns False
bool("any non-empty string") returns True
+ 4
Now I understand the algorithm of Boolean operator..! I should have researched more about it! Thanks for giving me the detailed answer and make me think about the basic principles of Boolean operator! Have a nice day!
0
You're welcome! Have a nice day, too.