FAQ: Learn Python: Function Arguments - Default Arguments

This community-built FAQ covers the “Default Arguments” exercise from the lesson “Learn Python: Function Arguments”.

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

Learn Python 3

FAQs on the exercise Default Arguments

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!

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

Need broader help or resources? Head here.

Looking for motivation to keep learning? Join our wider discussions.

Learn more about how to use this guide.

Found a bug? Report it!

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!

2 posts were split to a new topic: Code Argument Alternative Doesn’t Work?

Hi there, does anyone know what the import os does in this excercise? How does it function within the codecademy environment?I’ve read about it in the pydocs, but didn’t understand everything of it. Does it let us simulate an os so we can create folders and files?

Thanks :slight_smile:

In the Default Arguments module - you can set default values. In the example you can then pass only 1 argument to a function with two parameters. Is there a way to pass only one argument that is the second parameter and then has the default in the first?
For Example:
def create_user(username=None, is_admin=False):

Can we call a create_user(True) in some way?

yes, we can:

create_user(is_admin=True)

or:

create_user(None, True)

or:

create_user(username=None, is_admin=True)

create_user(True) is known as positional argument, given the position of the argument determines the parameter belongs to.

create_user(username=None, is_admin=True) is known as (If I am not mistaken, been a while since I have done python) as keyword arguments. Given we now rely on a keyword rather then position for the arguments to match with the parameters.

I believe we can even do:

create_user( is_admin=True, username=None)

would be a illogical thing to do, just showing the possibilities.

Thanks @stetim94! 2 lessons later they went into this! Appreciate your quick response!

1 Like