-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
-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
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 True
or 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 python python-3.x
You are not signed in. Login or sign up in order to post.
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 aif light_x > initial_tx: esquerda...
try to edit your ask and further clarify what you want– Luiz Augusto
Could you be clearer in explaining your problem because the question code itself answers?
– Augusto Vasques