L3·Functions & Modules
🧩Defining Functions
def, return, default arguments, docstrings.
defreturndocstring
§ 1def
def name(params): body. Return with return; without it, returns None.
§ 2Default arguments
Evaluated once at definition. Never use mutable defaults like [] or {} — use None + assign inside.
§ 3Docstrings
First string in the body becomes .__doc__. Show up in help().
Animated step-through
step 1 / 6// Call greet('Ada')
1def greet(name, greeting="Hello"):2 """Return a friendly greeting."""3 return f"{greeting}, {name}!"45print(greet("Ada"))6print(greet("Bob", greeting="Hi"))Variables
— none yet —
Call stack
<module>
Try it live · Python runs in your browser
Loading playground…
Checkpoint quiz
Question 1 / 2
What does 'return' with no value give?