Creating a Function:
To create a function in Python, we use the def keyword followed by the function name and a pair of parentheses () which may include optional parameters. The function body is defined using indentation.
Syntax:
def function_name():
# body of the function
statement(s)E.g:-
def say_hello():
print("Hello, World!")In this example:
defis the keyword used to define the function.say_hellois the name of the function.- The function body prints “
Hello, World!” when the function is called.
Calling a Function:
To call or execute a function, simply use the function name followed by parentheses.
say_hello()