Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Functions

By: Neec0 on Jul 11th, 2013  |  syntax: Python  |  size: 0.91 KB  |  views: 6  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #Use def to "define" a function.  Below we are telling python to def the
  2. #function "is_it_even".  Functions are followed by an optional argument, in
  3. #the case below, I am using the "x" as a placeholder for that argument.
  4. #It takes the value of "x" and passes it into the function.  Inside the
  5. #function it runs the code against the argument of "x", checking to see if x
  6. #is divisble by 2.
  7.  
  8. def is_it_even(x):
  9.     if x % 2 == 0:
  10.         return True
  11.     else:
  12.         return False
  13.  
  14. # here we are going to "call" the function by printing its name and giving it
  15. # an argument for "x".
  16.  
  17. print is_it_even(8)
  18. print is_it_even(9)
  19.  
  20.  
  21.  
  22.  
  23. # Most functions are used for bigger and better things than checking for even
  24. # numbers. Often they are used inside other objects called Classes.  These
  25. # classes are the foundation of most extensive programs. When functions are used
  26. # inside a Class they are referred to as methods.
clone this paste RAW Paste Data