Learn
Learn Python: Function Arguments
Using Keyword and Positional Arguments
Not all of your arguments need to have default values. But Python will only accept functions defined with their parameters in a specific order. The required parameters need to occur before any parameters with a default argument.
# Raises a TypeError def create_user(is_admin=False, username, password): create_email(username, password) set_permissions(is_admin)
In the above code, we attempt to define a default argument for is_admin
without defining default arguments for the later parameters: username
and password
.
If we want to give is_admin
a default argument, we need to list it last in our function definition:
# Works perfectly def create_user(username, password, is_admin=False): create_email(username, password) set_permissions(is_admin)
Instructions
1.
In script.py the function get_id
tries to define a parameter with a default argument before a required parameter.
Update the function signature of get_id
so that website
comes second and html_id
comes first.