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


what is a argument in python?

so im confused, what is argument?

If i make a function called def one(two) and write code below, it says two is not defined .. even if i do like two = "three" in my code, so what is a argument for, can it be any string or list i want? i've been confused with arguments sense i've seen them

2 Answers

An argument is a value passed into a function. It can be any value: a number, a string, a float, or a list are just some examples. The argument is then used within the function, and the function would spit out ("return") a value. You may think that some functions don't return values—like print—but functions that "don't return a value" really returns None.

Think of it like this: a function is a little machine that takes in argument(s) and spits out a value, depending on that value. For example, you could have a multiply function, and it can take in two arguments. Let's call these arguments num1 and num2. multiply would return the product of num1 and num2.

A function in fact doesn't need to take arguments, but it is less common. Usually functions take arguments. :+1:

I hope this helps!

Happy coding! :zap: ~Alex

18,877 Points

Arguments are values given to a function.

A function takes some inputs and can generate some output. Your arguments are the inputs into that function.

To use your example. If we create a function named 'one' that takes one argument, like this:

def one(two):
    return output

You could then use this function to double a value:

x = one(10)
y = one("hello")
z = one(True)

Now, x should equal 20, y = "hellohello" and z = 2. Outside of the definition/scope of your function there is no variable 'two.' It is a parameter of your function that (1) is used to allow arguments to be put into the function (if you wanted multiple arguments/inputs you could have multiple parameters - def one(input1, input2, input3)) and (2) can be used within the body of the function to generate output.

When we type one(10), we ask python to run the code in our one function with the parameter 'two' equal to our argument 10. Or "hello" or True, or whatever else we want to try to input.

Just play around making and using simple functions and it will make sense very quickly.