Skip to content
On this page

Functions

Defining Functions:

Functions are reusable blocks of code that perform a specific task.

python
# Function definition
def greet(name):
    return f"Hello, {name}!"

Parameters and Return Values:

Functions can have parameters (input) and return values (output).

python
# Function with parameters and return value
def add(a, b):
    return a + b

Lambda Functions:

Lambda functions are small anonymous functions defined using the lambda keyword.

python
# Lambda function
multiply = lambda x, y: x * y