You are on page 1of 7

Function assignment

Q-1. What is the default return value for a function that does not
return any value explicitly?

Q-2. Which of the following items are present in the function


header?

A. function name
B. function name and parameter list
C. parameter list
D. return value

Q-3. Which of the following enclose the input parameters or


arguments of a function?

A. brackets
B. parentheses
C. curly braces
D. quotation marks

Q-4. Which keywords marks the beginning of the function block?

Q-5. What is the name given to that area of memory, where the
system stores the parameters and local variables of a function call?

A. a heap
B. storage area
C. a stack
D. an array
Q6Write python statement in the given missing line which will
correctly represent the function body in the given code snippet?

def f(number):

# Missing function body

print(f(5))

Q7. What is the output of the following code snippet?

def func(message, num = 1):


print(message * num)

func('Welcome')
func('Viewers', 3)
Q8. What is the output of the following code snippet?

def myfunc(text, num):


while num > 0:
print(text)
num = num - 1
myfunc('Hello', 4)
Q9. What is the output of the following code snippet?

def func(x = 1, y = 2):


x = x + y
y += 1
print(x, y)

func(y = 2, x = 1)

Q10. What is the output of the following code snippet?

num = 1
def func():
num = 3
print(num)

func()
print(num)

Q11. What is the output of the following code snippet?

num = 1
def func():
num = num + 3
print(num)

func()
print(num)

Q12. What is the output of the following code snippet?

num = 1
def func():
global num
num = num + 3
print(num)

func()
print(num)

Q12.  What is the output of the following code snippet?


def test(x = 1, y = 2):
x = x + y
y += 1
print(x, y)

test(2, 1)

Q13. Which of the following function headers is correct?

A. def f(a = 1, b):


B. def f(a = 1, b, c = 2):
C. def f(a = 1, b = 1, c = 2):
D. def f(a = 1, b = 1, c = 2, d):
Q14. What is the output of the following code snippet?

myList = [lambda x: x ** 2,
lambda x: x ** 3,
lambda x: x ** 4]

for f in myList:
print(f(3))

Q15. What is the output of the following code snippet?

def func( mylist ):


mylist = [1,2,3,4];
print ("Values inside the function: ", mylist)
return

mylist = [10,20,30];
func( mylist );
print ("Values outside the function: ", mylist)

Q16. What is the output of the following code snippet?

x = 50
def func():
global x

print('x is', x)
x = 2
print('Changed global x to', x)
func()
print('Value of x is', x)

Q17. Which of the following function calls can be used to invoke the
below function definition?

def test(a, b, c, d)

A. test(1, “2”, “3”, “4”)


B. test(a = 1, 2, 3, 4)
C. test(a = 1, b = 2, c = 3, 4)
D. test(a = 1, b = 2, c = 3, d = ‘d’)
E. test(1, 2, 3, d = 4)

Q18. def myfunc(text, num):

while num > 0:


num = num - 1

num=4
myfunc('Hello', num)

19. What is the output of the following code snippet?

def func(x = 1, y = 2):


return x + y, x - y

x, y = func(y = 2, x = 1)
print(x, y)

20. What is the output of the following code snippet?

def func():
text = 'Welcome'
name = (lambda x:text + ' ' + x)
return name

msg = func()
print(msg('All'))

21. What is the output of the following code snippet?

def func(x, y=2):


num = 1
for i in range(y):
num = num * x
return num
print (func(4))
print (func(4, 4))

22. What is the output of the following code snippet?


def addFunc(item):
item += [1]

mylist = [1, 2, 3, 4]
addFunc(mylist)
print (len(mylist))

23. What is the output of the following code snippet?

myList = [1, 2, 3, 4, 5]
def func(x):
x.pop()
x.pop()
x.insert(-1, 0)
print ("Inside func():", x)

func(myList)
print ("After function call:", myList)

24. Find O/P:

def f(value, values):


v = 1
values[0] = 44
t = 3
v = [1, 2, 3]
f(t, v)
print(t, v[0])
Q25. What will be the output of the following code snippet?
data = [[[1, 2], [3, 4]], [[5, 6], [7, 8]]]
def fun(m):
v = m[0][0]

for row in m:
for element in row:
if v < element: v = element

return v
print(fun(data[0]))

Q26. What will be the output of the following code snippet?


fruit = {}
def add(index):
if index in fruit:
fruit[index] += 1
else:
fruit[index] = 1

add('Carrot')
add('Beet Root')
add('Tomato')
print (len(fruit))

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)
Q What will be the output of the following Python code?
1. x = 50
2. def func():
3. global x
4. print('x is', x)
5. x = 2
6. print('Changed global x to', x)
7. func()
8. print('Value of x is', x)
 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)
5. def maximum(x, y):
6. if x > y:
7. return x
8. elif x == y:
9. return 'The numbers are equal'
10. else:
11. return y
12.  
13. print(maximum(2, 3))

This set of Python Questions for entrance examinations focuses on “Functions”.

1. 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
View Answer
Answer: d
Explanation: None.
2. What are the two main types of functions?
a) Custom function
b) Built-in function & User defined function
c) User function
d) System function
View Answer
Answer: b
Explanation: 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.
3. Where is function defined?
a) Module
b) Class
c) Another function
d) All of the mentioned
View Answer

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


a) Module
b) Class
c) Another function
d) Method
View Answer
Answer: d
Explanation: None.
5. 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
View Answer
Answer: a
Explanation: Each object in Python has a unique id. The id() function returns the object’s id.
6. Which of the following refers to mathematical function?
a) sqrt
b) rhombus
c) add
d) rhombus
View Answer
Answer: a
Explanation: Func

You might also like