How do I find the difference between two values without knowing which is larger?
问题 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. >>>distance(6,3) 3 >>>distance(3,6) 3 Obviously I could write a simple definition to calculate which is larger and then just do a simple subtraction: def distance(x, y): if x >= y: result = x - y else: result = y - x return result but I'd rather not have to call a custom function like this. From my limited experience I've