+5 votes
in Programming Languages by (73.8k points)
If no return statement is specified in a function, what value will it return?

1 Answer

+1 vote
by (349k points)
selected by
 
Best answer

A function returns the None object by default if the "return" statement is not mentioned in the function. A return statement with no expression in it also returns None.

Here are examples:

Without return statement

>>> def fnc(a,b):
...     c=a+b
...
>>> print(fnc(2,3))
None

Return without any expression

>>> def fnc(a,b):
...     c=a+b
...     return
...
>>> print(fnc(2,3))
None


...