Here are few rules to define a function in Python.
Function blocks begin with the keyword def followed by the function name and parentheses ( ( ) ).
Any input parameters or arguments should be placed within these parentheses. You can also define parameters inside these parentheses.
Parameters (arguments) through which we pass values to a function. They are optional.
The code block within every function starts with a colon (:) and is indented.
Optional documentation string (docstring) to describe what the function does.
The statement return [expression] exits a function, optionally passing back an expression to the caller. A return statement with no arguments is the same as return None.
Let us see a python function that finds the even and odd number.
# A simple Python function to check
# whether data is even or odd
def evenOdd( data ):
if (data % 2 == 0):
print "even"
else:
print "odd"
# Function Call
evenOdd(27)
evenOdd(6)
Answer :
Here are few rules to define a function in Python.
Let us see a python function that finds the even and odd number.
Output:
odd
need an explanation for this answer? contact us directly to get an explanation for this answereven