Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python

"IF NOT"

I'm trying to understand exactly what the code is asking?

x = 4 y= 2 if not 1 + 1 == y or x == 4 and 7 == 8: print("Yes") elif x > y: print("No")

I'm confused about what an "if" statement is asking of a Boolean.

1 Answer

Steven Parker
Steven Parker
215,939 Points

This looks like a test of your understanding of operator associativity.

The "not" part of this expression just inverts the result of the comparison "1 + 1 == y" so the entire thing means "if y is not equal to 2".

Everything after the "or" in the larger expression is meaningless since 7 will never equal 8.

Great explanation! that gives me much more clarity. Whenever the code can be "translated" that helps every time. thanks!