Functions: #6 Practice Makes Perfect


#1

I don't understand why...

def cube(n):
    n = n ** 3
    return n

works, and...

def cube(n):
    return n ** 3

Also works, but...

def cube(n):
    return n = n ** 3

does not work. Can anyone explain why this third method does not work?


#2

return does not work with a statement, only an expression (or nothing). That is why we refer to it as the return value.

n = n ** 3

is a statement.


#4