Member-only story
*args, **kwargs, and Everything in Between
The fundamentals of function parameters and arguments in Python
Python has become the go-to language in Data Science for its versatility, simplicity, and powerful libraries. Functions, with their ability to encapsulate reusable code, play a key role in streamlining and enhancing the data science workflow in Python. Understanding the nuances of function arguments and parameters is essential for harnessing the true potential of Python functions in the context of Data Science.
Parameters v Arguments
The first thing to understand when working with functions in Python is the difference between parameters and arguments. A parameter is a variable within a function definition, while an argument is what you pass into the function's parameters when you call it. For example:
def my_func(param1, param2):
print(f"{param1} {param2}")
my_func("Arg1", "Arg2")
# Out:
# Arg1 Arg2
param1
and param2
are functional parameters, while "Arg1"
and "Arg2"
are the arguments.
Positional v Keyword arguments
In this example, “Arg1” and “Arg2” are passed in as positional arguments. This is because the parameter that each argument relates to are not specified in the…