12/19 On Beyond Strings : (*args) and (args)?


Hi everyone!

Sorry but I think that I’ve missed something!
Why does it means to put an * before the argument of a fonction??
It appears on the first 2 but not the last one.

def biggest_number(*args):
print max(args)
return max(args)

def smallest_number(*args):
print min(args)
return min(args)

def distance_from_zero(arg):
print abs(arg)
return abs(arg)

biggest_number(-10, -5, 5, 10)
smallest_number(-10, -5, 5, 10)

Thank you (anyone who have time to answer) :slight_smile:



*args is a special parameter for function, it gives you a tuple (immutable list). You can see this:

def biggest_number(*args):
    print args
    print max(args)
    return max(args)

biggest_number(-10, -5, 5, 10)

the function has only a single parameter, but multiple arguments at function call. Normally this wouldn’t work, but because of *args it does


Ah OK!
Thank you very much stetim94!!


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