Exercises · Q7
Q.Does a function always return a value? Explain with an example.
CBSENCERTSubjective· 3mImportance★★★★★est
63% · 25/40 Questions
You're viewing a preview — the full solution, concept, methods & PYQ mapping are locked.
Start your 14-day free trial to unlock the full solution →Not in the useful sense: a function with no return statement (or a bare return) implicitly hands back the special value None — so technically every call yields something, but only a return <expression> gives a meaningful result.
The idea. Python functions split into two informal kinds: fruitful functions that compute and return a value, and procedure-like functions that just perform an action (printing, saving, drawing). Python unifies them by making the action-only kind return the special stand-in object None automatically.
# A function WITHOUT return — performs an action only
def show(msg):
print(msg)
# A function WITH return — produces a value
def square(n):
return n * n
result1 = show("Hello") # show prints, then returns None implicitly
result2 = square(6)
print(result1)
print(type(result1))
print(result2)
Expected output
Hello
None
<class 'NoneType'>
36
How it works
- Calling
show("Hello")executes the body (printingHello); since the body ends without areturn <value>, Python returnsNone, which lands inresult1. - A bare
return(no expression) behaves identically — it exits early and returnsNone. square(6)has an explicitreturn n * n, so the call evaluates to 36. …
Unlock everything free for 14 days
- Full step-by-step solutions
- Concept-first explanations
- Methods, shortcuts & mistakes
- PYQ mapping + timed mock tests
Full access for 14 days. No credit card required.