Concept
Return values: `return` vs `None`
`return` sends a calculated answer back to the caller and exits the function. Without `return`, functions silently hand back `None`.
python
def add(a, b):
return a + b
result = add(10, 5)
print(result) # 15
# 90. Return values: `return` vs `None` `return` sends a calculated answer back to the caller and exits the function immediately. Without `return`, functions silently hand back `None`: ```python def add(a, b): return a + b result = add(10, 5) print(result) # 15 ``` Classic beginner mistake: Writing `print(a + b)` inside the function and forgetting `return`. That shows the answer on your screen, but gives nothing back to your code to use in calculations.
Checkpoint
What does a function return if you omit the `return` statement?
Practice
Write a function `square(n)` that returns `n * n`. Call it with `4` and print the returned result.
01
Tap code blocks below to assemble
Available Blocks