Value of a variable to be equal to the comparison of two variables

Asked

Viewed 37 times

-2

For example how do I make a variable equal to a comparison of two variables as in this code

esquerda = light_x > initial_tx
direita = light_x < initial_tx
baixo = light_y > initial_ty
cima = light_y < initial_ty
  • Welcome, equal to a comparison? is not very clear what you want, the variable esquerda will receive the value of the largest? or the smallest? Make a if light_x > initial_tx: esquerda... try to edit your ask and further clarify what you want

  • Could you be clearer in explaining your problem because the question code itself answers?

1 answer

0


A Python comparison, either between variables, or between direct values, will always result in an object Bool - with True or False value.

The sign of = simply resove the expression right first, and bind the name left to the result of the expression.

That is, a line like esquerda = light_x > initial_tx first makes the comparison light_x > initial_tx, that will result in Trueor False, and then keeps that value associated with the name "left".

There is no secret. In practice, you can, in sequence, use the variable esquerda diet within a if, instead of doing if light_x > initial_tx: you can use direct if esquerda:.

Your doubt was a little ambiguous, but I hope I’ve clarified what you wanted to understand.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.