In our simple example, there isn't much of a difference.
In a real-world example, the *args and *kwargs syntax give us more options in how we accept data into our function.
The decision is largely one between:
A) forcing the use of structured data, and...
B) not needing to know the structure in advance.
In your example, we must always pass in a list or dictionary, even if we are only passing in a single hobby. (This approach is not necessarily bad -- it may, in fact, be the right solution.) If, instead, we allow variable-length arguments -- by using the *args or *kwargs syntax -- then we do not need to structure the data in advance.
A more in-depth discussion related to your question can be found here.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
What is the difference if I just used list or dictionary as arguments?
def my_hobbies(hobbies_list):
print("My hobbies: " + ", ".join(hobbies_list))
In our simple example, there isn't much of a difference.
In a real-world example, the
*args
and*kwargs
syntax give us more options in how we accept data into our function.The decision is largely one between:
A) forcing the use of structured data, and...
B) not needing to know the structure in advance.
In your example, we must always pass in a list or dictionary, even if we are only passing in a single hobby. (This approach is not necessarily bad -- it may, in fact, be the right solution.) If, instead, we allow variable-length arguments -- by using the
*args
or*kwargs
syntax -- then we do not need to structure the data in advance.A more in-depth discussion related to your question can be found here.