The big if-explain please


#1



Hi,so I completed the exercise correctly but I didn't understand why?
Can someone please explain me how this code works and how do I use "the_flying_circus()" function in an if statement?
Thanks,


def the_flying_circus():
    if 50!=10:   
        return True
    elif  not 500==600 and 400==6:
       return True
        
    else:
       return the_flying_circus() == True


#2

okay, normally when you have a function:

def example():
   print "hello world"

you add the function call after the function so the function executes:

def example():
   print "hello world"
example()

if you only want to execute the function if some condition is true you can do:

def example():
   print "hello world"
if True:
   example()

now the function call (which will execute the function) is only executed if the condition is true.

nesting a function call inside the function is possible, it is called recursion, but for now, i wouldn't do this, don't nest the function call inside the function


#3

okay thank you it really helped


#4

the other fun thing you can do:

def example():
    return True
if example() == True:
   print "The function returns true"

in the if condition, the function gets executed, it gets something in return, what is returned is compared with True, if it equals, execute the if clause


#5

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