What are functions in Python?

A function is a block of code which is executed only when it is called. To define a Python function, the def keyword is used. You can pass data, known as parameters, into a function. A function can return data as a result.

Example

def my_function(name):
    print("Hi, Welcome to",name)

# Calling the function
my_function("ProgramsBuzz");

Output: Hi, Welcome to ProgramsBuzz.