Q. Is return statement optional ? Compare and comment on the following two return statements :


return

return val


Answer :-

The return statement is optional ONLY WHEN the function is void or we can say that when the function does not return a value. A function that returns a value, must have at least one return statement.

From given two return statements, statement

return

is not returning any value, rather it returns the control to caller along with empty value None. And the statement

return val

is returning the control to caller along with the value contained in variable val.

Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post