FAQ: Introduction to Functions - Parameters

This community-built FAQ covers the “Parameters” exercise from the lesson “Introduction to Functions”.

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

Computer Science
Data Science

FAQs on the exercise Parameters

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: Where do I enter my function?

2 posts were split to a new topic: What do I need to change to delete “number = 5”?

4 posts were split to a new topic: Is passing a number in the same as using that number as the argument?

3 posts were split to a new topic: What is the difference between a parameter and an argument?

Hi, It has accepted my answers to this exercise and I can see the “Next” button but I am getting the following comment

Did you change the name of mult_two_add_three to mul_x_add_y ?

What’s the significance of this?
Thanks,

In the one case, we always add three after we multiply by two. What if we wish to make the multiplier variable? What about making the addend variable, too? That is where the variables x and y come into play. They are symbolic of any value, not just a fixed two and three, respectively.

We can replicate the initial function by using default parameters.

def mul_x_add_y(n, x=2, y=3):
    return n * x + y

That will do exactly what we expect with a single argument in the function call…

print (mul_x_add_y(6))    #  15

It follows, though, that such a function would, could, should return an identity when no second and third positional argument is supplied.

def mul_x_add_y(n, x=1, y=0):
    return n * x + y
print (mul_x_add_y(6))    #  6

Now we can multiply two values…

print (mul_x_add_y(6, 7))    #  42

Or add two values…

print (mul_x_add_y(6, 1, 7))    #  13

Bottom line, we have made this function truly re-usable and fluid. One chunk of code, infinite numbers of variable uses.

1 Like

I have a question! Is the term “argument” only used in the context of functions? In the exercise it is defined as “the information that is to be used in the execution of the function” and the “value [that is] between the parentheses when we call the function.”

Is “argument” used in any other kind of scenarios or is it only used when you are talking about functions? If it is used elsewhere, in what other contexts might I find that term used?

print ('value')

In the above, 'value' is the argument given in the call to the print() function. We can see that arguments apply to all functions, not just our own. Our code essentially extends the standard library by adding custom functions.

Arguments are the objects we feed into the function, and parameters are the variables that identify them in function scope.

Thanks for the explanation! This is helpful. I appreciate it!

1 Like

Now, modify the function definition so that it has a parameter called number . Then delete the number = 5 assignment on the first line of the function.

Pass the number 1 into your function call.

i’m still don’t understand how i can do tha:

Is the actual parameter the same thing as the argument?

They are related, but not the same.

parameter  =>  variable

argument   =>  object

The variable is locally defined so shut off from the outside world. It is what the object will be known by within the function.

1 Like

Ah I see. So the argument is an object, i.e. a thing that always exists, whereas the actual parameter refers to the data inside that object, which possibly changes with every function call.

Thank you!

1 Like

The answer to the below program is 8 and 19.
My question is when mult_two_add_three() is called, the argument 5 is not passed.
Instead only number 8 is passed as an argument. The behaviour of the function is bit confusing.

def mult_two_add_three(number):
    number = 8
    print(number)
    print(number*2 + 3)
   
mult_two_add_three(5)

We can perhaps manipulate the parameter within our function, but we would not overwrite it, directly out of the gate. If that line is removed, we get access to the actual argument.

Thanks for your reply.
This means that code inside the function(i.e parameter within our function is given priority).

But it is not protected. We must protect it, or dismantle/mutate it carefully, and purposefully.

def sum_sq(a,b):
  n_a = a+b
  n_b = b+a
  def sq(n_a,n_b):
    return (n_a)**2 + (n_b)**2
sum_sq(12,43)

Can I pass parameters from another function in a nested function like this? Why is this returning None value? Why isn’t the inner func. not getting executed even?

Hello @ricky_rick and welcome to the Codecademy Forums!

Yes, you can pass parameters from another function into a nested function, as long as the function to which you are passing the parameters is nested under the appropriate function (consider the scope of variables).

None is returned by default for all functions. Your code is returning None because there isn’t a return statement for sum_sq. You’ve defined the sq function inside sum_sq, but sq is never called. Because sq is never called, it doesn’t execute and sum_sq ends up having nothing to return, resulting in None.

1 Like