Function

def calculate_sum(numbers):
    """
    Calculate the sum of a list of numbers.

    Args:
        numbers (list): A list of numbers to calculate the sum of.

    Returns:
        float: The sum of the numbers in the list.
    """
    total = 0
    for num in numbers:
        total += num
    return total
# *args function
def print_args(*args):
    """
    Print all the arguments passed to the function.

    Args:
        *args: A variable-length argument list.
    """
    for arg in args:
        print(arg)

# **kwargs function
def print_kwargs(**kwargs):
    """
    Print all the keyword arguments passed to the function.

    Args:
        **kwargs: A variable-length keyword argument list.
    """
    for key, value in kwargs.items():
        print(key + " = " + str(value))
# Lambda function to add two numbers
add_numbers = lambda x, y: x + y

# Call lambda function
result = add_numbers(3, 5)
print(result)  # Output: 8
pyth
def greet(name="World"):
    """
    Print a greeting message.

    Args:
        name (str): The name to greet. Default is "World".
    """
    print("Hello, " + name + "!")

# Call function with default parameter value
greet()  # Output: Hello, World!

# Call function with a specific parameter value
greet("John")  # Output: Hello, John!

Last updated