Functions and Modules

Functions in Python

Functions in Python are defined using the def keyword.

Example:

def greet(name):
    return f"Hello, {name}!"

print(greet("Alice"))  # Output: Hello, Alice!

Lambda Functions

Lambda functions are anonymous functions defined using the lambda keyword.

Example:

multiply = lambda x, y: x * y
print(multiply(3, 4))  # Output: 12

Modules in Python

Modules allow us to organize our code into separate files and reuse them.

Example:

import math
print(math.sqrt(16))  # Output: 4.0