Before we can use a user-defined function, we need to create it. To declare a function, you use the def keyword followed by the function name, parentheses, and a colon. You can also specify parameters inside the parentheses if your function needs to accept input values. The function body is indented below the declaration.
Here’s an example of a simple function that takes two parameters and prints their sum:
def add_numbers(a, b):
sum = a + b
print("The sum is:", sum)
#
Login
Accessing this course requires a login. Please enter your credentials below!