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
0 Comments