def greet():
message = "Hello"
print(message)
greet()Line-by-line explanation
- The function is defined.
messageis created locally inside it.- The function can display message.
- The call runs the function.
Prefer parameters and return values over changing global variables. They make each function’s inputs and outputs visible.
Tiny Practice
Identify the local variable and display it inside the function.
Starter template
def show():
word = "local"
CHANGE_ME
show()Line-by-line explanation
- Word is created inside show.
- The missing line is inside the function.
Hint
- Use print.
- Pass
wordwithout quotes. - Keep indentation.
Show Solution
def show():
word = "local"
print(word)
show()Line-by-line explanation
- Word is local to show.
- It is displayed while in scope.
- The call runs the function.