Advertisements
Advertisements
प्रश्न
Does a function always return a value? Explain with an example.
थोडक्यात उत्तर
Advertisements
उत्तर
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 is 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--> 5shaalaa.com
या प्रश्नात किंवा उत्तरात काही त्रुटी आहे का?
