What is an argument in python?

The term ‘argument’ here is not defined? What’s an argument in the context of Python?

2 Likes

An argument is simply a value provided to a function when you call it. Once you learn functions, I would search videos that talk about parameters and arguments (becoming comfortable with these terms earlier will help later). It will make more sense when you learn functions.

Essentially, just like the examples states : “we can pass a variable as an argument to…”
So string1 is an argument in this lesson.

Also questions that have to do definitions are really easy to find online. There are a lot of great resources!

51 Likes

Arguments in a function are essentially “values” or sometimes “instructions” that are passed on or “feeded” to the function so that the function can compute the output.

Say I have a function called “add_numbers” which takes any two given integers and computes their sum. Here, in this specific function, the arguments will be the two integers “a” and “b” which will be passed into the function “add_numbers” to compute the output “a + b”.

As a matter of fact, even the print() function takes arguments. We can pass in a string, an integer, a variable, a boolean, etc into the print() function to compute a certain desired output. For example:
print(“hello world”) - here the argument is the string “hello world”
print(4) - here the argument is the integer 4
and so on… :smile:

38 Likes

I recently read about the difference between parameters and arguments specific to Python, and this explanation has been helpful for me. Comparing an argument to another Python component is easier for me to visualize, because the explanation will illuminate its role and how it contributes to Python functions overall.

As previously stated, arguments are values. Arguments are literal data (not a reference to data, but the data itself). For example, when defining a function, within the function signature, a parameter is an object that is like a placeholder or container (if you will) for arguments. Parameters are like containers that define the data that the function is designed to interpret/perform a task with. Parameters describe/hold the arguments that will get passed to the function, when the function is called. Parameters describe the data, while the arguments are the actual data. Of course, this is very general - and gets more complicated in later lessons / more complex code.

19 Likes

So in this exercise the variable age is the parameter and the integer 10 is the argument?

Apologies it’s not clear from the thread exactly which exercise you’re referring to but you’re probably right.

The following link from the docs- python: argument vs. parameter
might cover your concerns and the the glossary provides good descriptions of the two.

The parameter is effectively a name within the function itself whereas the argument is an object passed to the function. Within the def statement the names/identifiers would be parameters def func (par1, par2, *pars...) whereas calling the same function, e.g func(arg1, arg2, *args) would typically require passing arguments.

3 Likes

This helped me in ways I cant express thank you!!

So, this statement appears in the lesson but there is no other information. Can anyone help me understand this statement, " If you’re trying to print() a numeric variable you can use commas to pass it as a different argument rather than converting it to a string."?

All print does is output textual information. A fair few of the previous examples deliberately converted certain types like int to strings, e.g. str(3). So you’d see things like this which basically creates one big string and then prints it-

print("The output value is: " + str(3))

But print itself can get a textual representation of types like int using their __str__ or __repr__ methods so you can do things like print(3) which outputs a 3 in text form without requiring the user to explicitly do the conversion to a string beforehand.

What’s more print can accept multiple arguments like print(3, 5, 10) which outputs 3 5 10. So you could get the same output with each of the following-

print("The output value is: " + str(3))
print("The output value is:", 3)

# the second relies on the standard separator being a single whitespace...
print("The output value is:", 3, sep=' ')

I think that’s all they’re referring to, using multiple arguments (using commas) instead of concatenating all the arguments into one big string.

Later on you’ll probably run into string formatting which is significantly easier than either of those options but they’re worth knowing nonetheless.

Hello,
i hope my answer is not too late for everyone still asking what is an argument in python.

In Python, and just using the function we know until this lesson like the print() function which is used to output information to the console. The information you want to print is passed to the function as an argument.

For example, if you want to print the text “Hello, world!”, you would do it like this:

print(“Hello, world!”)

In this case, “Hello, world!” is the argument that you’re passing to the print() function. The function takes this argument and outputs it to the console.

You can pass multiple arguments to the print() function as well, and it will print them all out with a space in between. For example:

print(“Hello,”, “world!”)

In this case, “Hello,” and “world!” are both arguments to the print() function. The function prints both of them out, with a space in between.

I hope this helps clarify things!

1 Like