On Beyond strings



I had removed the return function. And it still works.

So why bother to put the return function?

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

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

def distance_from_zero(arg):
    print abs(arg)

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


It is python best practice to use return statements when creating functions. What return tells the interpreter is, "output this value from this function" whereas a print statement just says, "display value on to the console".

So basically,

return gives something back or replies to the caller of the function while print produces text.

hope this helps you understand. :slight_smile:


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