2024-04-24 16:36:59 发布
网友
显然
-1**2
返回值-1,而不是1
-1
1
所以我总是得到一个负值。如何让python为每个偶数指数返回一个正值
-x的优先级低于**
参见示例: http://www.tutorialspoint.com/python/operators_precedence_example.htm 因此:
>>> -1**2 -1 >>> (-1)**2 1
指数将首先计算,然后乘以系数-1
P - Parenthesis E - Exponents M - Multiplication D - and Division A - Addition S - and Substraction
-x的优先级低于**
参见示例: http://www.tutorialspoint.com/python/operators_precedence_example.htm 因此:
指数将首先计算,然后乘以系数-1
相关问题 更多 >
编程相关推荐