Functions MCQ
Functions MCQ
x is now 50
1. Which of the following is the use of function in python? b)
a) Functions are reusable pieces of programs
b) Functions don’t provide better modularity for your x is 50
application Changed local x to 2
c) you can’t also create your own functions x is now 2
d) All of the mentioned c)
Hello x is 50
Hello Changed global x to 2
d) None of the mentioned Value of x is 2
c)
x = 50 Hello
def func(x): World 5
print('x is', x) c)
x=2
print('Changed local x to', x) Hello
func(x) World,World,World,World,World
print('x is now', x) d)
a)
Hello
x is 50 HelloHelloHelloHelloHello
8. What will be the output of the following Python code? 3. Where is function defined?
a) Module
def func(a, b=5, c=10): b) Class
print('a is', a, 'and b is', b, 'and c is', c) c) Another function
d) All of the mentioned
func(3, 7)
func(25, c = 24)
func(c = 50, a = 100) 4. What is called when a function is defined inside a
a) class?
a) Module
a is 7 and b is 3 and c is 10 b) Class
a is 25 and b is 5 and c is 24 c) Another function
a is 5 and b is 100 and c is 50 d) Method
b)
5. Which of the following is the use of id() function in
a is 3 and b is 7 and c is 10 python?
a is 5 and b is 25 and c is 24 a) Id returns the identity of the object
a is 50 and b is 100 and c is 5 b) Every object doesn’t have a unique id
c) c) All of the mentioned
d) None of the mentioned
a is 3 and b is 7 and c is 10
a is 25 and b is 5 and c is 24
a is 100 and b is 5 and c is 50 6. Which of the following refers to mathematical
d) None of the mentioned function?
a) sqrt
b) rhombus
9. What will be the output of the following Python code? c) add
d) rhombus
def maximum(x, y):
if x > y:
return x 7. What will be the output of the following Python code?
elif x == y:
return 'The numbers are equal' def cube(x):
else: return x * x * x
return y x = cube(3)
print(maximum(2, 3)) print x
a) 2 a) 9
b) 3 b) 3
c) The numbers are equal c) 27
d) None of the mentioned d) 30
10. Which of the following is a feature of DocString? 8. What will be the output of the following Python code?
a) Provide a convenient way of associating
documentation with Python modules, functions, classes, def C2F(c):
and methods return c * 9/5 + 32
b) All functions should have a docstring print C2F(100)
c) Docstrings can be accessed by the __doc__ attribute on print C2F(0)
objects a)
d) All of the mentioned
212
Which are the advantages of functions in python? 32
a) Reducing duplication of code b)
b) Decomposing complex problems into simpler pieces
c) Improving clarity of the code 314
d) All of the mentioned 24
c)
6 10
100 56
c) b)
123 45
12345 56
d) None of the mentioned c)