Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #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
- else:
- 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.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement