Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Python Basics (2015) Logic in Python Product

What is a argument?

so my last task, i was trying to produce "Hi " a multiple of times so it would look like Hi Hi Hi Hi Hi so it was def printer(count): print(count * "Hi ")

so i'm assuming count is the argument. i tried looking up arguments i could use for python. and it was just confusing haha.

i managed to pass my task with a much much better understanding thanks to the help of the community, but i still don't understand what a argument is. does it have its own special property?

i get how i can call them whatever i want, but the vastness of that confuses me.

def product(count, interger):
    print({} * {}.format(count, interger))

product(5 * 6)

1 Answer

28,523 Points

Technically speaking, count in the previous task is not actually an argument, it is a parameter. Arguments and parameters are closely linked but they are not the same thing.

Let's start with a simple example, say I wanted to make a function that takes two numbers and performs addition on them, and then returns the result. That would look like this:

# Defining function add
def add(num1, num2):
    return num1 + num2

# Calling function add
add(5, 10)

Above I first define a function with two parameters, the first is num1 and the second is num2. Parameters can be thought of as variables that are given a value when the function is called. So even though you don't give them a value inside your function you can treat them as variables that do have a value, since they will be assigned one when the function is called.

After defining the function I call it. When you call a function you can pass arguments to it inside the parenthesis. 5 is the first argument and 10 is the second argument. Arguments passed to a function is assigned to the parameters of the function based on their position. That is to say that the first argument is assigned to the first parameter and so on. That means that num1 is assigned 5 and num2 is assigned 10.

Arguments are separated using a comma, just like you do when you define multiple parameters for a function.

Looking at the example above you should be able to figure out how to solve the task at hand, but if you are still confused about anything then feel free to ask me more questions, I'll answer anything I can.

best explanation ever, thankyou!