On Beyond strings


#1



https://www.codecademy.com/en/courses/python-beginner-c7VZg/3/1?curriculum_id=4f89dab3d788890003000096


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)
distance_from_zero(-10)


#2

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:


#3

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