FAQ: Introduction to Functions - Parameters & Arguments

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

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

Visualize Data with Python
Data Scientist
Analyze Data with Python
Computer Science
Analyze Financial Data with Python
Build Chatbots with Python
Build Python Web Apps with Flask
Data Analyst

Learn Python 3
CS101 Livestream Series

FAQs on the exercise Parameters & 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!
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!

Can you assign anything else to an argument besides text?

Hi, I noticed something on this exercise, it’s just a little thing. Not a criticism!

There are no indentations in the blue and yellow function in your descriptive text before the two lines that start with print in the function. That might be a small error(?)

it looks like this

def trip_welcome(destination):
print(" Welcome to Tripcademy! “)
print(” Looks like you’re going to the " + destination + " today. ")

…anyways. I’m loving the Python course <3

So I understand the successful implementation of parameters and arguments thus far,

def generate_trip_instructions(location):

print("Looks like you are planning a trip to visit " + location)

print("You can use the public subway system to get to " + location)

generate_trip_instructions(“Central Park”)

Everything here works as it should, but my question is more toward the logic of it. Why does it work? If Python is a top down read. How is it that we can call a function, and print out (“string” + parameter), but the parameter is defined after we call the function?

Similar to if we were to print a variable, but define the variable after we try to print, it would error out and say that the variable isn’t defined. Just throws me for a loop a bit. I was really caught up on this one for awhile, as I kept trying to define the parameter before the function and it continually errored.

1 Like

It might help to think of calling the function as a way of creating a second mini program. It has its own names and instruction set but it’s empty. It’s only when you call it and pass arguments to it that it actually gets loaded to memory that those names are assigned to actual data/objects. What’s more you can call it more than once with entirely different values and the names are just assigned to these new values and the same instructions are executed.

The function call effectively acts like a temporary assignment to that parameter function(parameter=argument). It is used in the mini program, it returns a value and then it is simply forgotten once that function has finished executing. So the names/variables in your new mini program stay the same but what they refer to changes on each new call.

def func(x): return x + 4 # The new function has a parameter x # This parameter is effectively empty # Only when we call it does something get assigned print(func(2)) # Once the value is returned what `x` refers to is forgotten print(func(5)) # If it helps you can use the following syntax for this example... print(func(x=10))

I appreciate the reply!

I figured it out the next day, after a solid night sleep and some brain debugging… It was kind of a stupid question once it dawned on me. I sometimes get into the thick of it, and kind of forget the basics. “See the forest through the trees” kinda scenario.

It makes perfect sense now. As soon as we use def __ folllowed by the indents, its all self contained and nothing is being ran. Once we call the function with its argument, that argument is applied to the function, and the function is ran beneath the calling of it… thus its still operating top down…

My brain just saw, “hey, that stuff is above it! How is it working like that?” :roll_eyes:

Anyway, I appreciate the in-depth response as it helps me reinforce my understanding of it thus far!

1 Like

I have a problem with this code. I typed it out and looks the same as the person above but it will not show that it is correct

Codecademy export · GitHub.

This is for Parameters & Arguments section 6 part 2.

1 Like

‘Parenthesis’ should be ‘Parentheses’ – also maybe make it clearer early on that a parameter has a name and an argument has a value…

I have issues printing out the result after i type the correct code. can you please explay this for me

Three issues:

  • You wrote the argument as "Cenetral Park". It should be "Central Park".

  • In your function call, you spelled the function as generate_trip_instruction. It should be generate_trip_instructions.

  • The function call needs to be outside the function definition. You have the function call at the same indentation as the body of the function, which means the function call is interpreted as being part of the body of the function. Instead, the function call shouldn’t be indented.

def generate_trip_instructions(location):
    print(...
    print(...

generate_trip_instructions("Central Park")
# No indentation
1 Like

can you please explain what wrong in my code…i input the code correctly and still yet telling me there is an error

Unlike some other languages, indentation is important in Python (Some languages use curly braces etc. instead of indentation to indicate the body of a function/method).

In Python, the statements meant to be the body of the function must be indented. The function call is not part of the body of the function and should therefore not be indented.

def generate_trip_instructions(location):
    print("Looks like you are planning a trip to visit " + location)
    print("You can use the public subway system to get to " + location)

generate_trip_instructions("Central Park")

The print statements are meant to be in the body of the function and are therefore indented.

The function call is not part of the function and is not indented.

2 Likes

not sure why it’s asking if i wrote the code, I don’t see anything that i missed

update: I only added a space between to and the last " and only then did it let me move on, does this matter?

@css6020759884 based on your code the code isn’t finished? You need it to print the full sentence:

Looks like you are planning a trip to visit

Hi @cloud6659013659 , I had the same error initially and it’s because without the space, your location is going to go right against the rest of your print statement and therefore not the intended output.

Check the difference below:

def generate_trip_instructions(location): """ Generates trip intructions based on user-inputted location """ print("Looks like you are planning a trip to visit " + location) print("You can use the public subway system to get to " + location) def generate_trip_instructions_with_no_space(location): """ Generates trip intructions based on user-inputted location (this one has no space) """ print("Looks like you are planning a trip to visit" + location) print("You can use the public subway system to get to" + location) generate_trip_instructions("Central Park") generate_trip_instructions_with_no_space("Central Park")

@java3142839019 you can set other variable types like integer, float, boolean, etc to your parameters as long as you have coded the function body to accomodate the intended variable type the arguments will be.

In this example, depending on how you coded the body of your print text, you could have entered integers, but may throw an error if you concatenated the parameter variable in your print rather than using the comma method.

Hi Codeacademy team,

Loving the course but this one, section Parameters & Arguments section 6, part 2 was incredibly confusing and frustrating all because of what looks like one space.

I had

Your code below:

def generate_trip_instructions(location):
print(“Looks like you are planning a trip to visit”+ location)

Which didnt work, I could for life of me realise why, then I added one space after the “t” in visit and it is green, see below.

Your code below:

def generate_trip_instructions(location):
print("Looks like you are planning a trip to visit "+ location)

I get you probably have a test running in the background but my god can you not add the potential answer without space or make the hint a little clear to use the space?

Hi, other than parsing through the function definition, is there a way to see how many parameters and what type are expected when calling the function?