19/19 "Choose any argument you like". What's an "argument"?


In the final part of the Functions lesson the instructions tell me that I can use any argument in the function being defined. Because the code seemed to be about identifying the type of the argument, I put in the integer of “-138”. After several error messages, I gave up and looked at the code. This is what was revealed:

def distance_from_zero(num):
if type(num) == int or type(num) == float:
return abs(num)
return “Nope”

This code completes the final part (19/19) of the Functions lesson. I replaced the argument “num” with what I had initially tried (-138, and additionally 138, 123 and some others) and this is the error I got:

File “python”, line 1
def distance_from_zero(-138):
SyntaxError: invalid syntax

I believe there is a possibility that I’m not quite clear on what an “argument” is, in this case, and then also how that differs from a “parameter”. Is there any reason why the code works with “num” and not some other argument, say, “…any argument [I] like”?



look at this code:

# function definition with parameter
def example(parameter):
    print parameter

# function call with argument 

so when we declare the function, we define a parameter. The parameter is going to receive an argument from the function call, so under the hood, this is happening:


which is why the parameter has to be a valid variable, otherwise you get an error given the assignment of argument to parameter will fail


thank you. so ‘num’ is a parameter that takes an argument in the form of a number that is either an integer or a float. i couldn’t recall that detail it seems.
thanks for your thorough explanation.


the argument can also be a string or boolean, why wouldn’t that be possible? Then the function uses type() to determine if the argument is float or integer.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.