Absolute Value Function

  • Share this:

Code introduction


Calculates and returns the absolute value of a number. If the input number is negative, it returns its opposite; if the input number is non-negative, it returns itself.


Technology Stack : Python built-in types and comparison operators

Code Type : Function

Code Difficulty :


                
                    
def abs_value(number):
    if number < 0:
        return -number
    else:
        return number