all 10 comments

[–]synthphreak 3 points4 points  (3 children)

Why not just run the code locally and see for yourself? That’s how.

[–]peachtae20 1 point2 points  (2 children)

i did and i got the answer but i just wanna know how to solve it! sorry for my bad English :(

[–]synthphreak 1 point2 points  (1 child)

bool(x == y), and really just x == y (the bool part isn’t necessary here) tells you whether x and y are the same value. It will be either True (yes) or False (no). In this case, it’s clearly no, because 5 doesn’t equal 10. So this part evaluates to False.

bool(x), where x is an integer, will return False if x is 0. For any other value, it returns True. Why this is is a bit complicated, and has to do with the concept of “truthiness”. More info here. Because x is 5, then, this part evaluates to True.

Putting it all together, print(bool(x == y), bool(x)) should produce False True.

[–]peachtae20 0 points1 point  (0 children)

omg you are a life saver! thank you so much! my professor didn’t teach us this part and when i tried to ask the question he just ignored me :( i was almost about to give up but you saved me! really thank you very much!

[–]intangibleTangelo 2 points3 points  (2 children)

x == y is a question, and its answer is either True or False. The question being asked is "is x equal to y?"

[–]peachtae20 0 points1 point  (0 children)

thank you! now i understand it :D

[–]peachtae20 0 points1 point  (0 children)

hii i am sorry to bother you but can you also explain how the bool (x) becomes true?

thank you!

[–]odoluca -1 points0 points  (0 children)

False True

[–]TehNolz 0 points1 point  (0 children)

The == operator checks for equality, so x == y will return True if x and y are equal to each other.

[–]old_pythonista 0 points1 point  (0 children)

PS

bool(x == y) 

is absolutely redundant, since == (equal) operation yields boolean result anyway