Python Forum
why (a and b) different from (b and a)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
why (a and b) different from (b and a)
#2
Look at https://docs.python.org/3/library/stdtyp...and-or-not

If you have result = expression1 and expresion2 and expression3 when interpreter will evaluate the expressions from left to right and:
if all are True, the value of result will be the last expression that is True (expression3)
if not all are True (e.g. expression2 is False) the value of result will return the first False value (i.e. expression2).

If you have result = expression1 or expresion2 or expression3, then:
if any is True, result value will be the first True value
if all are False, result value will be last False value

In your case both a and b are True (non-empty tuples), so it always returns the second one

it will be good to look at https://docs.python.org/3/library/stdtyp...ue-testing
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

Reply


Messages In This Thread
why (a and b) different from (b and a) - by oloap - Apr-07-2020, 07:24 PM
RE: why (a and b) different from (b and a) - by buran - Apr-07-2020, 08:03 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020