Q:

Write the steps to define the function in python

0

Write the steps to define the function in python

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Answer : 

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)

Output:

odd
even

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Python Interview Questions and Answers

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
How to call a function in python?... >>
<< What is a function in Python Programming?...