Neec0 Jul 11th, 2013 6 Never
- #Use def to "define" a function. Below we are telling python to def the
- #function "is_it_even". Functions are followed by an optional argument, in
- #the case below, I am using the "x" as a placeholder for that argument.
- #It takes the value of "x" and passes it into the function. Inside the
- #function it runs the code against the argument of "x", checking to see if x
- #is divisble by 2.
- def is_it_even(x):
- if x % 2 == 0:
- return True
- return False
- # here we are going to "call" the function by printing its name and giving it
- # an argument for "x".
- print is_it_even(8)
- print is_it_even(9)
- # Most functions are used for bigger and better things than checking for even
- # numbers. Often they are used inside other objects called Classes. These
- # classes are the foundation of most extensive programs. When functions are used
- # inside a Class they are referred to as methods.
RAW Paste Data