Parameters and Arguments
Parameters are variables defined in the function declaration, and arguments are the actual values passed to the function when it is called.
Example:
def greet_user(name):
print(f"Hello, {name}!")
greet_user("Carlos") # 'Carlos' is an argument
Types of Arguments:
- Positional: Assigned by order.
- Keyword: Specified by the parameter name.
- Default: Defined with a default value.
- Variable-length: Use args for tuples and *kwargs for dictionaries.
def show_info(name, age=18):
print(f"Name: {name}, Age: {age}")
show_info("Ana") # Uses default value for age
show_info("Luis", 25)