I've been reading through this introductory book on Python, and I've been following along fairly well. Compared to C++, Python seems to make more sense to me. That is, until I reached a section on Logical Operators. I don't completely understand what I just typed in to IDLE, and the results that were returned. Here's what I read:
Python provides three logical operators: and, or, and not. Both and and or use short-circuit logic and return the operand that determined the result—they do not return a Boolean (unless they actually have Boolean operands). Let’s see what this means in practice: >>> five = 5 >>> two = 2 >>> zero = 0 >>> five and two 2 >>> two and five 5 >>> five and zero 0 If the expression occurs in a Boolean context, the result is evaluated as a Boolean, so the preceding expressions would come out as True, True, and False in, say, an if statement. >>> nought = 0 >>> five or two 5 >>> two or five 2 >>> zero or five 5 >>> zero or nought 0 The or operator is similar; here the results in a Boolean context would be True, True, True, and False. The not unary operator evaluates its argument in a Boolean context and always returns a Boolean result, so to continue the earlier example, not (zero or nought) would produce True, and not two would produce False.
I don't understand why "five or two" outputs the value of 5, or any of the "or" examples, or why using a Boolean would return True or False. In this example, is the "or" operator comparing the two variables? I'm sorry, I'm probably missing something very simple, but this section of the book made me feel very stupid, lol.
Thanks in advance for any and all help.