Python Python Basics Types and Branching Comparing values

Ethan Martin
PRO
Ethan Martin
Pro 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

adam n
adam n
57,283 Points

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
Pro 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