Functions
Define a function with def. Parameters go in parentheses and return sends a value back. Default values make a parameter optional.
Example
def greet(name, greeting="Hello"):
return f"{greeting}, {name}!"
print(greet("Ada"))
print(greet("Tunde", "Welcome"))Result
Hello, Ada! Welcome, Tunde!
Exercise
Define a function.
add(a, b):
return a + bQuiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.