wiz-icon
MyQuestionIcon
MyQuestionIcon
1
You visited us 1 times! Enjoying our articles? Unlock Full Access!
Question

Does a function always return a value? Explain with an example.

Open in App
Solution

A function does not always return a value. In a user-defined function, a return statement is used to return a value.
Example:

Program:
# This function will not return any value
def func1():
a = 5
b = 6

# This function will return the value of 'a' i.e. 5
def func2():
a = 5
return a

# The return type of the functions are stored in the variables
message1 = func1()
message2 = func2()

print("Return from function 1-->", message1)
print("Return from function 2-->", message2)



​​OUTPUT:
Return from function 1--> None
Return from function 2--> 5




flag
Suggest Corrections
thumbs-up
1
Join BYJU'S Learning Program
similar_icon
Related Videos
thumbnail
lock
We Are Made of Patterns I
MATHEMATICS
Watch in App
Join BYJU'S Learning Program
CrossIcon