Skip to content

Python Functions

In Python, a function is a reusable block of code that performs a specific task. Functions help organize code, improve reusability, and make programs more modular.

Example:

        
# Defining a function
def greet(name):
    """This function greets the person passed in as a parameter."""
    print("Hello, " + name + "!")

# Calling the function
greet("Alice")
        
    

In the example above, a function named greet is defined with a parameter name. The function prints a greeting message using the provided name. The function is then called with the argument "Alice."