Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有这个号码 a = 7 , b= 9
a = 7 , b= 9
现在我想减去这两个数字。
b - a = 2. 现在没关系
b - a = 2
但a -b = -2
a -b = -2
但我只想知道差异,即 2 而不是 -ve 或 +ve,就像我们有 mod 运算符
我怎么能在python中做到这一点
你想要abs(a - b),不是abs(abs(a)-abs(b))
abs(a - b)
abs(abs(a)-abs(b))
这应该这样做
In [57]: abs(2 - -9) Out[57]: 11 In [58]: abs(-1 - 5) Out[58]: 6
按照零比雷埃夫斯的建议,只保留 1 个解决方案