Concept
Defining Functions with `def`
Wrap reusable logic inside a function using `def name():`. Invoke it anytime using `name()`.
python
def alarm():
print("INTRUDER ALERT!")
alarm() # Invokes the function!
# 88. Defining Functions with `def` Wrap reusable logic inside a function using `def name():`. Invoke it anytime using `name()`: ```python def alarm(): print("INTRUDER ALERT!") alarm() # Invokes the function! ``` Copy-pasting the exact same blocks of code across your files is a recipe for endless bugs. Define it once in a function, call it whenever needed.
Checkpoint
What keyword declares a new function in Python?
Practice
Define a function named `ping()` that prints `"pong"`. Call it once.
01
Tap code blocks below to assemble
Available Blocks