FAQ: Function Arguments: *args and **kwargs - Working with *args

This community-built FAQ covers the “Working with *args” exercise from the lesson “Function Arguments: *args and **kwargs”.

Paths and Courses
This exercise can be found in the following Codecademy content:

FAQs on the exercise Working with *args

There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply (reply) below.

If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!
You can also find further discussion and get answers to your questions over in Language Help.

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head to Language Help and Tips and Resources. If you are wanting feedback or inspiration for a project, check out Projects.

Looking for motivation to keep learning? Join our wider discussions in Community

Learn more about how to use this guide.

Found a bug? Report it online, or post in Bug Reporting

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!


I tried with writing this code with one function i.e. assign table. Why would someone write two functions when we can update the previous function and the work can be done in one function?

I’m not sure that the instructions intended for a redefinition of assign_table.

If you meant you combined assign_and_print with assign_table then perhaps you could but be careful of functions, classes, modules or otherwise that do too much. This drifts into the realm of software engineering/design but it’s good to consider from the start, functions that do too much are harder to read and understand, harder to debug, harder to change in the future and far less flexible.

In the given example each of these functions is actually doing something quite different, the first one assigns a table to someone. if you compare this to the reality of a restaurant service this is much like seating guests (or perhaps assigning a server) to a table, but they may not be ready to immediately order. Therefore combining the assignment into the order might be a mistake as you have to start re-using the same function for different tasks.

Having the second function to make the order separate keeps the code clear and organised and more closely mirrors the reality of the restaurant service.

If you have the time starting to look at some best practices for programming might be a worthwhile investment for working in the future.

3 Likes

Thanks a lot!
Do you recommend any other resources to practice more?

1 Like

Hmm, the whole topic is a bit broad and a lot of it is based on opinion as much as anything else. I think the best general guidance is to find one or more good quality code bases that are in your field and try to somewhat mimic what they do.

There are various books that try to introduce generic guidance, clean code, the pragmatic programmer and hundreds more. Equally there are various guides and cookbooks for best practices in a particular language. I think it’s just one of those things to keep in mind and try to slowly absorb, yes you should listen to the voice of experience and let that advice influence your work but dropping everything to study “best practices” is probably less helpful than actually just practising and trying to soak things up bit by bit.

The new order items is in a tuple (due to *args making a tuple) and the original item entry (juices /pancakes) isn’t in a tuple. Seems like this would cause problems later if this was a real project…?

2 Likes

Also curious as to why this happens. The first order is created via tables, but the second we pass with a function. Regardless of the method, the neurotic in me seeks the consistency in the output.