Created
May 14, 2014 16:11
-
-
Save benjaminEwhite/2f1d4ee75536e64ebe14 to your computer and use it in GitHub Desktop.
function calling function example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def print_function(): | |
""" I'm also a function, but I don't take any parameters""" | |
print "I'm {}, and I'm printing now".format(print_function.__name__) | |
def subtractor(a, b): | |
"""I subtract b from a and return the result""" | |
print "I'm a function. My name is {}".format(subtractor.__name__) | |
print "I'm about to subtract {} and {}".format(a,b) | |
return a - b # i output a value by using the return statement | |
def function3(a=1, b=1): | |
""" I'm a function that calls other functions """ | |
print "I'm {} and I'm about to call subtractor function".format(function3.__name__) | |
total = subtractor(a,b) | |
print "I'm {} and I'm about to call print_function".format(function3.__name__) | |
print_function() | |
print "I'm {} and I'm about return total".format(function3.__name__) | |
return total | |
if __name__ == '__main__': | |
total = function3() | |
print "total is {}".format(total) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment