FAQ: Function Arguments: *args and **kwargs - All together now!

This community-built FAQ covers the "All together now! " 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 _All together now! _

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!

Hello group !,

(1) Why does not it work if I add the positional argument appetizer =?
(2) What would be the order for this to work ?

single_prix_fixe_order(appetizer= 'Baby Beets',
                       'Salmon', 'Scallops',
                        sides= 'Mashed Potatoes', 
                        ice_cream_scoop1='Vanilla', 
                        ice_cream_scoop2='Cookies and Cream')

Thank you in advanced

Hello. I’m not sure, but to my understanding, Python can handle positional arguments, keyword arguments, as well as multiple positional arguments or multiple keyword arguments as long as you respect the syntax order explained in the lesson:

Standard positional arguments
*args
Standard keyword arguments
**kwargs

So, if you pass a keyword for the appetizer in this case, it would no longer be a positional argument but a keyword argument instead. This changes the order in which arguments are handled and can result in a syntax error.

Again, this is my understanding, and perhaps a more experienced coder can provide a more accurate response.

Four years later, one thinks hardly going to be the case, as needs be. This OP is long gone and not waiting this long for an answer.

The member’s reply is not invalid, and may even be an apt response in a current question, if one can be found. That would be where to look for whom to help: Who is online today or within the last two weeks? They could use the help.

This topic is long dead. Be advised that I will be flagging it for moderation and your post may very well be deleted and this topic closed. Your time is better spent giving help to those who need it in the present rather than resurrecting long moribund topics.

2 Likes

Hello, thank you very much for your comments.

The spirit of the message was not to provide an answer to a question from many years ago, which obviously has either already been addressed or is no longer relevant to the author. Instead, the spirit was to provide an answer to a question that remained unanswered in the forums, in case another student (like myself) came across it.

Personally, after completing each lesson, I come to the forums to see what other students have asked and how other users have responded to those questions (through this complementary and self-imposed mandatory reading, I have found valuable information that enhances the learning experience on Codecademy). That was the idea behind answering the question, with my limited knowledge, and perhaps someone more experienced would correct me, leaving a record in the forum for posterity.

However, I understand moderation and the idea of not keeping old posts, so if the comment is deleted, it is completely understandable.

2 Likes

It is not for me to decide, as I am no longer a moderator. It was flagged but the present moderation team (paid Community Managers) may have chosen to ignore the flag.

I get what you’re saying, and you are not alone in your ambitions, it is quite natural for members to think that way. When a topic is really old and seemingly unresolved it may well indicate that the question is either moot, or it can be quickly answered by reading docs, etc. which is always encouraged. Part of learning to code in any language is also learning to find the documentation and online examples to study and learn from.

My concern today is that moot topics are best left alone to just drift away (moderators should be closing these topics so that can happen). Don’t let this overshadow your ambition and beliefs, but just keep that question in the back of your mind: Who is this really going to help? If the answer is probably nobody, then no sense resurrecting a dead topic. If you have NEW information and insight that you’ve garnered from your reading and research, then by all means share it.

1 Like

Hi there, why does this code return a syntax error:

def single_prix_fixe_order(appetizer, *entrees, sides, **dessert_scoops):
    print(appetizer)
    print(entrees)
    print(sides)
    print(dessert_scoops)

single_prix_fixe_order('Baby Beets', 'Salmon', 'Scallops', sides='Mashed Potatoes', dessert_scoops ='Vanilla',  'Cookies and Cream' )

The correct answer separates two ice cream flavors. But what’s wrong with the above?

Splats must not be followed by identifiers. sides is out of place. It should be before *entrees in the arguments list.

1 Like

Gotcha. Thanks as always!

1 Like