Python MCQ’s on Function: SET 5

41. Which are the advantages of functions in python?

a) Reducing duplication of code

b) Decomposing complex problems into simpler pieces

c) Improving clarity of the code

d) All of the mentioned

Check Answer

Answer: d
None.

42. What are the two main types of functions?

a) Custom function

b) Built-in function & User defined function

c) User function

d) System function

Check Answer

Answer: b
Built-in functions and user defined ones. The built-in functions are part of the Python language. Examples are: dir(), len() or abs(). The user defined functions are functions created with the def keyword.

43. Where is function defined?

a) Module

b) Class

c) Another function

d) All of the mentioned

Check Answer

Answer: d
Functions can be defined inside a module, a class or another function.

44. What is called when a function is defined inside a class?

a) Module

b) Class

c) Another function

d) Method

Check Answer

Answer: d
None.

45. Which of the following is the use of id() function in python?

a) Id returns the identity of the object

b) Every object doesn’t have a unique id

c) All of the mentioned

d) None of the mentioned

Check Answer

Answer: a
Each object in Python has a unique id. The id() function returns the object’s id.

46. Which of the following refers to mathematical function?

a) sqrt

b) rhombus

c) add

d) rhombus

Check Answer

Answer: a
Functions that are always available for usage, functions that are contained within external modules, which must be imported and functions defined by a programmer with the def keyword.
Eg: math import sqrt
A sqrt() function is imported from the math module.

47. What will be the output of the following Python code?

def cube(x):

return x * x * x

x = cube(3)

print x

a) 9

b) 3

c) 27

d) 30

Check Answer

Answer: c
A function is created to do a specific task. Often there is a result from such a task. The return keyword is used to return values from a function. A function may or may not return a value. If a function does not have a return keyword, it will send a none value.

48. What will be the output of the following Python code?

def C2F(c):

return c * 9/5 + 32

print C2F(100)

print C2F(0)

a)

212
32

b)

314
24

c)

567
98

d) None of the mentioned

Check Answer

Answer: a
The code shown above is used to convert a temperature in degree celsius to fahrenheit.

49. What will be the output of the following Python code?

def power(x, y=2):

r = 1

for i in range(y):

r = r * x

return r

print power(3)

print power(3, 3)

a)

212
32

b)

9
27

c)

567
98

d) None of the mentioned

Check Answer

Answer: b
The arguments in Python functions may have implicit values. An implicit value is used, if no value is provided. Here we created a power function. The function has one argument with an implicit value. We can call the function with one or two arguments.

50. What will be the output of the following Python code?

def sum(*args):

”’Function returns the sum

of all values”’

r = 0

for i in args:

r += i

return r

print sum.__doc__

print sum(1, 2, 3)

print sum(1, 2, 3, 4, 5)

a)

6
15

b)

6
100

c)

123
12345

d) None of the mentioned

Check Answer

Answer: a
We use the * operator to indicate, that the function will accept arbitrary number of arguments. The sum() function will return the sum of all arguments. The first string in the function body is called the function documentation string. It is used to document the function. The string must be in triple quotes.

Page  1  2  3  4  5  6  7

Python Interview Questions (MCQs)

We have divided these Python Questions and Answers into various parts based on the topics. Open the Topic of your choice and Practice these MCQs.

Python MCQs on Variables and Operators Python MCQs on Precedence and Associativity
Python MCQs on Data Type Python MCQs on Boolean
Python MCQs on Bitwise Operators Python MCQs on Formatting and Advance Formatting
Python MCQs on Decorators Python MCQs on While and For Loops
Python MCQs on List Python MCQs on List Comprehension
Python MCQs on String Python MCQs on Tuple
Python MCQs on SET Python MCQs on Dictionary
Python MCQs on Functions Python MCQs on Argument Parsing
Python MCQs on Global and Local Variables Python MCQs on Recursion
Python MCQs on Mapping Functions Python MCQs on Modules
Python MCQs on Regular Expressions Python MCQs on Files
Python MCQs on Overloading Python MCQs on Classes and Objects
Python MCQs on Inheritance Python MCQs on Polymorphism and Encapsulation
Python MCQs on Exception Handling

Leave a Comment