Chapter 3: Custom functions

Calling your custom function

face Josiah Wang

Once you have defined your function, then you can freely call it from your program as you would call a function from the Python standard library.

In our example, we write our function call from the same file as the function definition.

def absolute_value(number):
    if number < 0:
        return -number
    return number


n = input("Enter an integer: ")
while n != "quit":
    new_n = absolute_value(int(n))
    print(f"The absolute value is: {new_n}")
    n = input("Enter an integer: ")

You can also call functions defined outside of the file, but you will have to do something more. We will talk about this later in the course.