Return Keyword in Python with Example Program

Definition of the Return Keyword:

The return keyword is used in a function to send a result back to the code that called the function.


Syntax of return:

def function_name(parameters):
    # Code
    return value

Simple Example of Using the return Keyword:

Question :

Write a function add() that returns the sum of two numbers. Then, display the result.

Program:

def add(a, b):
    return a + b    # Returns the sum of a and b

result = add(5, 3)   # Calling the function
print(result)        # Output: 8

Post a Comment

0 Comments