Why are these two statements not equivalent?
>> math.pow(-2,2) 4.0 >> -2 ** 2 -4
Python 3.5.3 (default, January 19, 2017, 14:11:04)
Here the order of executing the operators is performed (operator priority): at -2**2first, raising to the power 2 of power 2 is performed, then the negative sign.
-2**2
Use parentheses to get the result you want.
(- 2) ** 2 = 4
since the priority “-” is behind the priority “**”, use (-2) ** 2 to calculate -2 first
Python3.
-2 ** 2
: -(2**2)= -4.
-(2**2)
-4
Source: https://habr.com/ru/post/1684578/More articles:Lost all commits on forced push in github - gitHow to determine when the status of the Alt key changes - javascriptHow to use dotnet (.NET Core) to pack a sln file that contains an sql project? - c #Strange regex behavior in R - regexHow can I call the returned inner function of another function? - javascriptSmart Broker против Dumb Broker (Kafka и RabbitMQ) - rabbitmqHow to build differently for Linux and Windows - goКруг для ответа на столкновение не работает как ожидается - javascriptJavaScript N-Body gravity modeling - javascriptSaving OAuth state token in Flask session - flaskAll Articles