How do I find the difference between two values without knowing which is larger?

前端 未结 11 2231
借酒劲吻你
借酒劲吻你 2020-12-11 14:22

I was wondering if there was a function built into Python that can determine the distance between two rational numbers but without me telling it which number is larger. e.g.

11条回答
  •  我在风中等你
    2020-12-11 14:57

    Just use abs(x - y). This'll return the net difference between the two as a positive value, regardless of which value is larger.

提交回复
热议问题