MENU

Chapter 10 Functions Solutions

Question - 21 : -
Write syntax for function that takes a string as input parameter and prints it on standard screen.

Answer - 21 : -

def printme (str):
“This prints a passed string into this function”
print str
return

Question - 22 : -
Why do we define a function?

Answer - 22 : -

● Decomposing complex problems into simpler pieces.
● Reducing duplication of code.

Question - 23 : -
When we can execute a function?

Answer - 23 : -

Once the basic structure of a function is finalized, we can execute it

Question - 24 : -
Are all parameters (arguments) in the Python language passed by reference.

Answer - 24 : -

Yes,All parameters (arguments) in the Python language are passed by reference.

Question - 25 : -
How do we define a function ?

Answer - 25 : -

Here are simple 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.
● The first statement of a function can be an optional statement – the documentation string of the function or docstaing.
● he code block within every function start with color(:) and is indented.
● 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.

Question - 26 : -
What are Required arguments?

Answer - 26 : -

Required arguments are the arguments passed to a function in correct positional order.

Question - 27 : -
Explain default argument.

Answer - 27 : -

A default argument is an argument that assumes a default value, if a value is not provided in the function call.

Question - 28 : -
Write the syntax of lambda functions?

Answer - 28 : -

The syntax of lambda functions contains only a single statement, which is as follows:
lambda[arg1 [,arg2, argn]] :expression

Question - 29 : -
What is a Python module ? What is its significance ? .

Answer - 29 : -

A ‘module’ is a chunk of python code that exists in its own (.pu) file and is intended to be used by python code outside iteself. Modules allow one to fundle together code in a form in which it can easily be used later.
The modules can be ‘imported’ in other programs so the function and other definitions in imported modules becomes availabe to code that imports them.

Question - 30 : -
“Python has certain functions that you can readily use without having to write any special code.” What type of functions are these ?

Answer - 30 : -

The pre-defined functions that are always available for use are known as python’s built-in functions. For example :
len (), type (), int (), raw-input () etc.

Free - Previous Years Question Papers
Any questions? Ask us!
×