Welcome to the “Defining Functions” tutorial!
Overview
Functions let you group reusable blocks of code under a name.
Syntax
def function_name(param1, param2=default_value):
    """
    Optional docstring: describe what the function does
    """
    # function body
    return result
Example
def add(a, b):
    return a + b
sum = add(3, 5)  # sum is 8
Key Takeaways
- Use defto declare a function.
- Parameters can have default values.
- Use returnto send back a result.
Happy coding!
Comments
Post a Comment