Jan-21-2019, 03:31 PM
(Jan-21-2019, 12:54 PM)j.crater Wrote: If you compare values in Python using "and" and "or" like this:THANK YOU SO MUCH !!! your post will save me from many future problems :)if (player1 and player2) == 911: if (player1 or player2) > 10:a Boolean comparison (True/False) is made. In this case, any nonzero number and non-empty string is True. When "and" comparison is used, values are checked sequentially and if they are all True, the last value is returned (in this case value of player2). In case of "or", values are checked sequentially, and when first value which is True is encountered, comparison stops and that value is returned (it may be player1 or player2). It works the same way even if you chain 100 values to be compared instead of just 2. There is no real science behind this, it's just how Python works. There is maybe a bit of an optimization trick here. If you compare by "and", you can put values that are most likely to be False first, so the checking is over quicker in case they are False. Likewise with "or", you can put values that are most likely to be True first, so checking can be over quicker. I don't think this is very relevant for your particular code, but just an extra info in case you find it useful to know :)