Google News
logo
Python Program to Let a Function Return a Value
In the following example of Python program that defines a function that takes two parameters and returns their sum :
Program :
def add_numbers(x, y):
    """
    This function takes two numbers as input and returns their sum.
    """
    return x + y

# Example usage of the add_numbers function
result = add_numbers(3, 5)
print(result)  # Output: 8
In this example, we define a function called `add_numbers` that takes two parameters, `x` and `y`. Inside the function, we simply return the sum of the two numbers.

We then call the function with two arguments, `3` and `5`, and assign the result to a variable called `result`. Finally, we print the value of `result`, which is `8`.