Skip to content

Instantly share code, notes, and snippets.

@Jwely
Last active October 19, 2015 21:34
Show Gist options
  • Save Jwely/f0d2359dec4857afb21c to your computer and use it in GitHub Desktop.
Save Jwely/f0d2359dec4857afb21c to your computer and use it in GitHub Desktop.
# quick overview of function definitions and function calls.
import some_module
# this below is a function definition, use it to generalize code to repeatedly do something.
# dnppy is full of function definitions
def my_function(argument1, argument2, default_argument3="some_default_string")
"""
this is a function DEFINITION , and this docstring should tell you
something about how it works. This docstring will be displayed if someone
uses "help(my_function)"
"""
# do some stuff
outputs = argument1 + argument2
return outputs
# if you were to call the function above from another script in this directory, you could use
from functions import my_function # the name of this script is "functions.py" we import from functions
my_outputs = my_function(input1, input2) # this is where we actually call the function using our inputs.
# if you are running a function WITHIN the dnppy script that defines it, you can do so without
# consequence by using the "magic" namespace variable "__name__" which will only be equal to
# "__main__" if THIS script is run. anything under this statement will NOT run if this script
# is imported from somewhere else, so it can be a good testing area.
if __name__ == "__main__":
test_outs = my_function(test_input1, test_input2)
print(test_outs)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment