Comparison Function for Integer Values

  • Share this:

Code introduction


The function is used to compare the size of two values and return the comparison result. If the two values are equal, it returns 0; if the first value is less than the second value, it returns -1; if the first value is greater than the second value, it returns 1.


Technology Stack : Comparison, conditional expressions

Code Type : Comparison function

Code Difficulty : Intermediate


                
                    
def aordiff(a, b):
    if a == b:
        return 0
    elif a < b:
        return -1
    else:
        return 1