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 trialeestsaid
1,311 PointsBoolean basics
What is the logic requiring (True and False) to be (True and True) to return True?
2 Answers
Chris Freeman
Treehouse Moderator 68,441 PointsBased 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 toTrue
will make the entire statementTrue
regardless of the other items. - For a statement with
and
, the first item to evaluate toFalse
will make the entire statementFalse
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
1,311 PointsPerfect, thanks.
eestsaid
1,311 PointsHard 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.
Chris Freeman
Treehouse Moderator 68,441 PointsChris Freeman
Treehouse Moderator 68,441 PointsCan you please restate your question please? Itβs not obvious what youβre asking.