What is a return statement? (Big If)


Hi all,
I'm trying to complete the python lessons, but I'm stuck on this exercise. It gives me the error message:

Oops, try again. the_flying_circus() returned the value None, did you forget to add a return statement?

I've found some older help posts that provide functional code, but I don't understand what a return statement is, and why this exercise requires one if it hasn't been introduced previously. Did I skip a lesson or something? How can I fix my existing code in order to complete this exercise?

# Make sure that the_flying_circus() returns True
def the_flying_circus():
    if (5 <= 5) and "Dog" == "Duck":    
        print "Monkeys can fly"
    elif (4 == 4) or "Dog" == "Duck":
        print "Birds can fly"
        print "Frogs can fly"


You have to use return statement instead of print!

A function can take values and process it and can..

1.return it using return statement.
2.It can print it
3.It can do both 1 and 2


So I just replace the 3 prints with 3 returns? and that's it?

What does return mean, anyway? Why don't they set up this exercise to use prints, like the example they provide?


return statement makes your function powerful,it makes your function to return a value..


def Double(x):
    print(2 * x)

when you call this function,it will print the double of a value..

Double(5) #it will print 10

You can't use it or save it for further use.

But by using return keyword we can return the value.

def Double(x):
    return 2 * x

Now your function does not print it but return it.

You can save the value inside a variable and use it later..

z = Double(4)

print z # will print 8

also check this thread ..

return statement


Okay, thanks for this information. It sounds like return is a way of saving a value for later parsing/use, etc.

I'm just confused about why they designed this lesson/exercise to use return, which hasn't been introduced yet, instead of print, which we've used in several of the preceding exercises.


Well sooner or later it has to come same as print function came.
Check the thread,I hope it helps you.
apart from theory of CC,do check docs of python at www.python.org


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