promotion image of download ymail app
Promoted
Anonymous
Anonymous asked in Computers & InternetProgramming & Design · 8 months ago

Difference between a parameter and an argument in Python?

Update:

Parameters: data that is passed into a function. Parameters are specific after the function name inside the parentheses.

Argument: a value that is being passed to a function call

Are these correct definitions EddieJ? They are from Automate the Boring Stuff by someone...

Update 2:

Thanks guys

2 Answers

Relevance
  • 8 months ago
    Favourite answer

    The parameter is the name used in the the function definition. The argument is the value passed when the function is called. For example:

    def cube_root(x):

    .... return x ** (1.0 / 3)

    The name "x" is a parameter. Later in the code you might see:

    r = cube_root(27)

    The value 27 is an argument; a value passed to the function. The function will use that value for x when running the statements in the function body.

    Edit: By the way, these definitions are shared with and probably inspired by the C programming language. Some other languages use "formal parameter" for the name in the function definition and "actual parameter" for the value in the function call, and some books and writers will use that terminology with every programming language--including Python, even though that's not what you'll find the Python's Language Reference document.

    About the update: Yes, that's good enough for starters. But the parameter is really the *name* used in the function definition, used to refer to the data (and not the data itself.)

    What I see in Automate the Boring Stuff (Chapter 3 - Functions) is: "A parameter is a variable that an argument is stored in when a function is called." And "variable" is a name that refers to a value, so that's really saing the same thing.

    • Commenter avatarLog in to reply to the answers
  • EddieJ
    Lv 7
    8 months ago

    If you want to draw a circle you need to supply a radius (or diameter).

    The general concept of what needs to be supplied -- the radius -- is the parameter. It is referred to by a reasonable variable name (such as radius) inside the function.

    The actual radius (such as 5), is the argument, and can be passed as either a numeric literal, or as a variable.

    Another way of saying it is that the argument is used in the calling routine (maybe the main program), where, yes, it is passed to the function. The parameter is used inside the function definition.

    You can say that the parameter takes on the value of the argument when the function is called.

    • Commenter avatarLog in to reply to the answers
Still have questions? Get answers by asking now.