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 #get-help.

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

Need broader help or resources? Head to #get-help and #community:tips-and-resources. If you are wanting feedback or inspiration for a project, check out #project.

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 #community:Codecademy-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.

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