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
क्या इस प्रश्न या उत्तर में कोई त्रुटि है?
