Create a greeting function
python · static example
def greet(name):
return f"Hello, {name}!"
message = greet("Asha")
print(message)The function accepts one parameter and returns a formatted string.
Package a task into a function so it can be called with different values.
A function is a named block of reusable code. Parameters receive input values. return sends a result back to the caller; print() only displays a value.
python · static example
def greet(name):
return f"Hello, {name}!"
message = greet("Asha")
print(message)The function accepts one parameter and returns a formatted string.
Hello, Asha!Labeled sample only — nothing was run on this page.
What does `return` do in a function?
Pick an answer to check.