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 Python Basics Types and Branching Comparing values

Ethan Martin
Ethan Martin
Courses Plus Student 1,883 Points

answer = 3.14 <= 3.14 -> Why is this true?

answer = 3.14 <= 3.14

I get that 3.14 is <= 3.14

However, isn't this a bool statement? Wouldn't this be evaluated as... "answer = 3.14" is false -> "False <= 3.14" is false.... right? Where is the error in my thinking

Thank you for all the help guys!

1 Answer

Everything to the right of the assignment operator (equal sign) gets evaluated before it is assigned to the variable.

So, here we first evaluate:

3.14 <= 3.14

Which is True. Python takes that True and then does something like:

answer = True

Let me know if this helps here

Ethan Martin
Ethan Martin
Courses Plus Student 1,883 Points

Thank you! I should have realized "answer" was a variable. Not a string that is being compared to the other values