Python Function Q&A - 1
Python Function Q&A - 1
Python Function Q&A - 1
return
mylist = [10,20,30];
func( mylist );
x = 50
def func():
global x
print('x is', x)
x = 2
func()
print('Value of x is', x)
A. x is 50
Changed global x to 2
Value of x is 50
B. x is 50
Changed global x to 2
Value of x is 2
C. x is 50
Changed global x to 50
Value of x is 50
D. None of the mentioned
Click here to view the answer.
Answer. B
Q-3.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 = 4)
E. test(1, 2, 3, d = 4)
Click here to view the answer.
Answer. A,D and E
B and C leads to SyntaxError: positional argument follows keyword argument
test(25, c = 24)
A. a is 7 and b is 3 and c is 10
a is 25 and b is 5 and c is 24
a is 5 and b is 100 and c is 50
B. a is 3 and b is 7 and c is 10
a is 5 and b is 25 and c is 24
a is 50 and b is 100 and c is 5
C. 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
D. None of the above
Click here to view the answer.
Answer. C
num = num - 1
num=4
myfunc('Hello', num)
A. 4
B. 3
C. 0
D. 1
Click here to view the answer.
Answer. A
Q-6. What is the output of the following code snippet?
return x + y, x - y
x, y = func(y = 2, x = 1)
print(x, y)
A. 1 3
B. 3 1
C. The program has a runtime error because the function returns the multiple values
D. 3 -1
E. -1 3
Click here to view the answer.
Answer. D
def func():
text = 'Welcome'
return name
msg = func()
print(msg('All'))
A. Welcome All
B. All Welcome
C. All
D. Welcome
Click here to view the answer.
Answer. A
Q-8. What is the output of the following code snippet?
min = (lambda x, y: x if x < y else y)
print(min(101*99, 102*98))
A. 9997
B. 9999
C. 9996
D. 9998
A. 8
16
B. 16
256
C. 32
1024
D. 128
1256
mylist = [1, 2, 3, 4]
addFunc(mylist)
print (len(mylist))
A. 2
B. 4
C. 5
D. An exception is thrown
Q-13. What is the order of usage of *args, **kwargs, and formal args in
function header?
A. str
B. int
C. tuple
D. list
E. dict
A. str
B. int
C. tuple
D. list
E. dict
func(myList)
print ("After function call:", myList)
A. [2, 3, 4, 5, 6, 7, 8]
B. [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47]
C. [2, 3, 5, 6, 7, 10, 15, 19, 20, 27, 35, 41, 49]
D. [2, 3, 5, 9, 13, 17, 26, 31, 35, 37, 41, 43, 47, 49]
A. [7, 2, 3, 5, 2, 6]
B. [30]
C. [7, 3, 4, 5, 6, 3]
D. [30, 23, 20, 15, 13, 7]
A. 47
B. 42
C. 102
D. 11