100% found this document useful (2 votes)
2K views4 pages

Functions MCQ

1. Functions provide reusability, modularity, and the ability to create custom functions in Python. The keyword used to define a function is 'def'. 2. Calling a defined function multiple times will print the same output multiple times. Functions allow code reuse through passing arguments. 3. Local variable changes inside a function do not persist outside the function. Global variables can be accessed and changed inside functions using the global keyword.

Uploaded by

Taru Goel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (2 votes)
2K views4 pages

Functions MCQ

1. Functions provide reusability, modularity, and the ability to create custom functions in Python. The keyword used to define a function is 'def'. 2. Calling a defined function multiple times will print the same output multiple times. Functions allow code reuse through passing arguments. 3. Local variable changes inside a function do not persist outside the function. Global variables can be accessed and changed inside functions using the global keyword.

Uploaded by

Taru Goel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

FUNCTIONS MCQ’S Changed local x to 2

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)

2. Which keyword is used for function? x is 50


a) Fun Changed local x to 2
b) Define x is now 100
c) Def d) None of the mentioned
d) Function

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


3. What will be the output of the following Python code?
x = 50
def sayHello(): def func():
print('Hello World!') global x
sayHello() print('x is', x)
sayHello() x=2
a) print('Changed global x to', x)
func()
Hello World! print('Value of x is', x)
Hello World! a)
b)
x is 50
'Hello World!' Changed global x to 2
'Hello World!' Value of x is 50
c) b)

Hello x is 50
Hello Changed global x to 2
d) None of the mentioned Value of x is 2
c)

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


Changed global x to 50
def printMax(a, b): Value of x is 50
if a > b: d) None of the mentioned
print(a, 'is maximum')
elif a == b:
print(a, 'is equal to', b) 7. What will be the output of the following Python code?
else:
print(b, 'is maximum') def say(message, times = 1):
printMax(3, 4) print(message * times)
a) 3 say('Hello')
b) 4 say('World', 5)
c) 4 is maximum a)
d) None of the mentioned
Hello
WorldWorldWorldWorldWorld
5. What will be the output of the following Python code? b)

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)

2. What are the two main types of functions? 567


a) Custom function 98
b) Built-in function & User defined function d) None of the mentioned
c) User function
d) System function
9. What will be the output of the following Python code?
3. What will be the output of the following Python code?
def power(x, y=2):
r=1 i=0
for i in range(y): def change(i):
r=r*x i=i+1
return r return i
print power(3) change(1)
print power(3, 3) print(i)
a) a) 1
b) Nothing is displayed
212 c) 0
32 d) An exception is thrown
b)

9 4. What will be the output of the following Python code?


27
c) def a(b):
b = b + [5]
567
98 c = [1, 2, 3, 4]
d) None of the mentioned a(c)
print(len(c))
a) 4
10. What will be the output of the following Python b) 5
code? c) 1
d) An exception is thrown
def sum(*args):
'''Function returns the sum
of all values''' 5. What will be the output of the following Python code?
r=0
for i in args: a=10
r += i b=20
return r def change():
print sum.__doc__ global b
print sum(1, 2, 3) a=45
print sum(1, 2, 3, 4, 5) b=56
a) change()
6 print(a)
15 print(b)
b) a)

6 10
100 56
c) b)

123 45
12345 56
d) None of the mentioned c)

What is a variable defined outside a function referred to 10


as? 20
a) A static variable d) Syntax Error
b) A global variable
c) A local variable
d) An automatic variable 6. What will be the output of the following Python code?

def change(i = 1, j = 2):


2. What is a variable defined inside a function referred to i=i+j
as? j=j+1
a) A global variable print(i, j)
b) A volatile variable change(j = 1, i = 2)
c) A local variable a) An exception is thrown because of conflicting values
d) An automatic variable b) 1 2
c) 3 3
d) 3 2

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

def change(one, *two):


print(type(two))
change(1,2,3,4)
a) Integer
b) Tuple
c) Dictionary
d) An exception is thrown

8. If a function doesn’t have a return statement, which of


the following does the function return?
a) int
b) null
c) None
d) An exception is thrown without the return statement

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

def display(b, n):


while n > 0:
print(b,end="")
n=n-1
display('z',3)
a) zzz
b) zz
c) An exception is executed
d) Infinite loop

10. What will be the output of the following Python


code?

def find(a, **b):


print(type(b))
find('letters',A='1',B='2')
a) String
b) Tuple
c) Dictionary
d) An exception is thrown

You might also like