Functions: Call and Reponse


#1



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

I correctly completed this section; however I was reviewing the code and cannot understand the reason for the following line:
return squared
I even deleted the line and the code still ran correctly. Can someone explain the reason this line was included, and what does the "return" action do?


def square(n):
    """Returns the square of a number."""
    squared = n**2
    print "%d squared is %d." % (n, squared)
    return squared
    
# Call the square function on line 9! Make sure to
# include the number 10 between the parentheses.
square(10)


#2

If you set square(10) to a variable, it would assign the value of squared to the variable.

E.g. This:

my_variable = square(10)

Would become this:

my_variable = 100

#3

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