0% found this document useful (0 votes)
29 views8 pages

Python Unit3 Fun MCQ

The document is a quiz on Python functions, covering topics such as function definition, usage, output of code snippets, and various function-related concepts. It includes multiple-choice questions that test knowledge on built-in functions, user-defined functions, recursion, and the behavior of functions in Python. The document serves as a study guide for understanding the fundamentals of functions in Python programming.

Uploaded by

arpanchhetri008
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
0% found this document useful (0 votes)
29 views8 pages

Python Unit3 Fun MCQ

The document is a quiz on Python functions, covering topics such as function definition, usage, output of code snippets, and various function-related concepts. It includes multiple-choice questions that test knowledge on built-in functions, user-defined functions, recursion, and the behavior of functions in Python. The document serves as a study guide for understanding the fundamentals of functions in Python programming.

Uploaded by

arpanchhetri008
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/ 8

UNIT 3- FUNCTIONS

1. Which of the following is the use of function in python?


a) Functions are reusable pieces of programs
b) Functions don’t provide better modularity for your application
c) you can’t also create your own functions
d) All of the mentioned
2. Which keyword is used for function?
a) Fun
b) Define
c) def
d) Function

3 What will be the output of the following Python code?

1. def printMax(a, b):


2. if a > b:
3. print(a, 'is maximum')
4. elif a == b:
5. print(a, 'is equal to', b)
6. else:
7. print(b, 'is maximum')
8. printMax(3, 4)

a)3 b) 4
c) 4 is maximum
d) None of the mentioned

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

1. def say(message, times = 1):


2. print(message * times)
3. say('Hello')
4. say('World', 5)

a) Hello
WorldWorldWorldWorldWorld
b) Hello
World 5
c) Hello
World,World,World,World,World
d) Hello
HelloHelloHelloHelloHello
5 What will be the output of the following Python code?

1. def maximum(x, y):


2. if x > y:
3. return x
4. elif x == y:
5. return 'The numbers are equal'
6. else:
7. return y
8.
9. print(maximum(2, 3))

a) 2
b) 3
c) The numbers are equal
d) None of the mentione

6 What is the primary purpose of a function in Python?

a)To execute a block of code repeatedly


b) To organize code into manageable units and promote code
reuse
c) To perform mathematical operations
d) To define conditional statements

7 Which of the following items are present in the function header?


A. function name
B. parameter list
C. return value
D. Both A and B
8 What is called when a function is defined inside a class?
A. class
B. function
C. method
D. module
9 If return statement is not used inside the function, the function will
return:
A. None
B. 0
C. Null
D. Arbitary value
10. Which of the following is the use of id() function in python?
A. Id() returns the size of object.
B. Id() returns the identity of the object.
C. Both A and B
D. None of the above
11. Lambda is a function in python?
A. True
B. False
C. Lambda is a function in python but user can not use it.
D. None of the above
12 Where is function defined?
A. Module
B. class
C. Another Function
D. All of the above

13 . How is a function declared in Python?


A. def function function_name():
B. declare function function_name():
C. def function_name():
D. declare function_name():

14 Choose the correct option with reference to below Python code?

def fn(a):

print(a)

x=90

fn(x)

A. x is the formal argument.


B. a is the actual argument.
C. fn(x) is the function signature.
D. x is the actual argument.
15 You can also create your own functions, these functions are called?
A. built-in functions
B. user-defined functions
C. py function
D. None of the above

16 Which one of the following is incorrect?


A. The variables used inside function are called local variables.
B. The local variables of a particular function can be used inside other
functions, but these cannot be used in global space
C. The variables used outside function are called global variables
D. In order to change the value of global variable inside function, keyword
global is used.
17 The code block within every function starts with a ?
A. ;
B. ::
C. :
D. %

18 ___________ are the arguments passed to a function in correct


positional order.
A. Required arguments
B. Keyword arguments
C. Default arguments
D. Variable-length arguments

19 Which of the following functions is a built-in function in python?

a) seed() b) sqrt() c) factorial() d) print()

20 What is a recursive function?


A. A function that calls other function.
B. A function which calls itself.
C. Both A and B
D. None of the above

21 What is the purpose of the return statement in a function?

a) To stop the execution of the function

b) To print a value to the console

c) To return a value to the caller

d) To define a recursive function

22 What will be the output of this program?

print(print(print("javatpoint")))

a javatpoint None None

b None None javatpoint


c None javatpoint None

d Javatpoint

23 What will be the output of the following Python code?

1. x = 50
2. def func(x):
3. print('x is', x)
4. x = 2
5. print('Changed local x to', x)
6. func(x)
7. print('x is now', x)

a) x is 50
Changed local x to 2
x is now 50
b) x is 50
Changed local x to 2
x is now 2
c) x is 50
Changed local x to 2
x is now 100
d) None of the mentioned

24 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

25 What are the two main types of functions?


a) Custom function
b) Built-in function & User defined function
c) User function
d) System function

26 Which of the following refers to mathematical function?


a) sqrt
b) rhombus
c) add
d) rhombus
27 What will be the output of the following Python code?

1. def cube(x):
2. return x * x * x
3. x = cube(3)
4. print x

a) 9
b) 3
c) 27
d) 30

28 Python supports the creation of anonymous functions at runtime, using a


construct called __________
a) lambda
b) pi
c) anonymous
d) none of the mentioned

29 What is a variable defined outside a function referred to as?


a) A static variable
b) A global variable
c) A local variable
d) An automatic variable

30 What is a variable defined inside a function referred to as?


a) A global variable
b) A volatile variable
c) A local variable
d) An automatic variable

31 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

32 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

33 What will be the output of the following Python code?

i=0
def change(i):
i=i+1
return i
change(1)
print(i)

a) 1
b) Nothing is displayed
c) 0
d) An exception is thrown

34 What will be the output of the following Python code?

def a(b):
b = b + [5]

c = [1, 2, 3, 4]
a(c)
print(len(c))

a) 4
b) 5
c) 1
d) An exception is thrown

35 . 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

36 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

37 Which of the following function headers is correct?


A. def fun(a = 2, b = 3, c)
B. def fun(a = 2, b, c = 3)
C. def fun(a, b = 2, c = 3)
D. def fun(a, b, c = 3, d)
38 In which part of memory does the system stores the parameter and
local variables of funtion call?
A. heap
B. stack
C. Uninitialized data segment
D. None of the above
39Which of the following will print the pi value defined in math
module?
A. print(pi)
B. print(math.pi)
C. from math import pi
print(pi)
D. from math import pi
print(math.pi)
40 Which one of the following is the correct way of calling a function?
A. function_name()
B. call function_name()
C. ret function_name()
D. function function_name()

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy