Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python

Passing arguments into functions

I understand how to define and utilize a function except when it comes to passing arguments in. Anyone have some tips, tricks, to get this straight in my head. Is the argument kind of like a variable, or maybe a place holder. Please share how you keep it straight in your head.

def knights(neee!):

Thanks,

Aaryn

1 Answer

Hi Erin,

I'll try my best!

parameters.python
# we define functions with parameters
# parameters are variables that are local to the function

def knights(message):
  print(message)

# outside of the knights function, there is no message variable
arguments.python
# we call functions by passing in arguments. these are 'values' that can either be variables or literals

arg = "neee!"

# here are two calls to the same function, passing in the same value for the argument

knights(arg)
knights("neee!")

# inside the function, the variable message holds the value "neee!" and gets printed to the screen

Hope this helps,

Cheers