Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

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 68,457 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 68,457 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.