Python Python Basics Types and Branching Logic

eestsaid
eestsaid
1,311 Points

Boolean basics

What is the logic requiring (True and False) to be (True and True) to return True?

Chris Freeman
Chris Freeman
Treehouse Moderator 56,648 Points

Can you please restate your question please? It’s not obvious what you’re asking.

2 Answers

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 56,648 Points

Based on your updated question

True or False returning True makes sense if I understand it correctly i.e. there is True or False in the statement so it returns True. True and False is however False and I'm not sure of the reasoning for this.

Python evaluates logical expressions in a lazy process.

  • For a statement with or, the first item to evaluate to True will make the entire statement True regardless of the other items.
  • For a statement with and, the first item to evaluate to False will make the entire statement False regardless of the other items.

If you have two items A and B and you want a True expression for when A is True and B is False, then use

if A and not B:

If B is False then not B is True.

Post back if you need more help. Good luck!!!

eestsaid
eestsaid
1,311 Points

Perfect, thanks.

eestsaid
eestsaid
1,311 Points

Hard to articulate but will give it a go.

True or False returning True makes sense if I understand it correctly i.e. there is True or False in the statement so it returns True. True and False is however False and I'm not sure of the reasoning for this.