- One of the best tools for following DRY Coding Principles
- Blocks of code that performs a specific task, like your phone's features.
- Can be reused, and helps make the program modular and manageable.
- Defining a function
def function_name(parameters):
# Code blocks
return value
- Calling a function
function_name(arguments)
- Children can access parent's scope
- Parents cannot access children's scope
- Returns a value from a function
- Also, immediately ends the function
- Multiple possible return values in a function
- Arguments are values you can pass to the function
- Parameters are variables that allows us to pass arguments to our function
- Positional Arguments: Arguments that are passed to a function in the correct positional order.
- Default Arguments/ Optional Parameters: Parameters that assume value if a value is not provided.
- Keyword Arguments: Arguments that are passed to a function by explicitly stating the parameter name.