Explore topic-wise MCQs in Testing Subject.

This section includes 657 Mcqs, each offering curated multiple-choice questions to sharpen your Testing Subject knowledge and support exam preparation. Choose a topic below to get started.

1.

Read the code shown below carefully and point out the global variables: y, z = 1, 2 def f(): global x x = y+z

A. x
B. y and z
C. x, y and z
D. Neither x, nor y, nor z
Answer» D. Neither x, nor y, nor z
2.

What is the output of the code shown below? x=100 def f1(): global x x=90 def f2(): global x x=80 print(x)

A. 100
B. 90
C. 80
D. Error
Answer» B. 90
3.

The output of code shown below is: x = 5 def f1(): global x x = 4 def f2(a,b): global x return a+b+x f1() total = f2(1,2) print(total)

A. Error
B. 7
C. 8
D. 15
Answer» C. 8
4.

What is the output of the code shown below? def f(x): print("outer") def f1(a): print("inner") print(a,x) f(3) f1(1)

A. outer error
B. nner error
C. outer inner
D. error
Answer» B. nner error
5.

What is the output of the code shown below? def f(p, q, r): global s p = 10 q = 20 r = 30 s = 40 print(p,q,r,s) p,q,r,s = 1,2,3,4 f(5,10,15)

A. 1 2 3 4
B. 5 10 15 4
C. 10 20 30 40
D. 5 10 15 40
Answer» D. 5 10 15 40
6.

What is the output of the code shown below? def f1(a,b=[]): b.append(a) return b print(f1(2,[3,4]))

A. [3,2,4]
B. [2,3,4]
C. Error
D. [3,4,2]
Answer» E.
7.

What is the output of the code shown? def f(): global a print(a) a = "hello" print(a) a = "world" f() print(a)

A. hello hello world
B. world world hello
C. hello world world
D. world hello world
Answer» C. hello world world
8.

What is the output of the following code? x=12 def f1(a,b=x): print(a,b) x=15 f1(4)

A. Error
B. 12 4
C. 4 12
D. 4 15
Answer» D. 4 15
9.

What is the output of the code shown below? def f1(x): global x x+=1 print(x) f1(15) print("hello")

A. error
B. hello
C. 16
D. 16 hello
Answer» B. hello
10.

What is the output of the code shown? def f1(): global x x+=1 print(x) x=12 print("x")

A. Error
B. 13
C. 13 x
D. x
Answer» E.
11.

What is the output of the code shown below? def san(x): print(x+1) x=-2 x=4 san(12)

A. 13
B. 10
C. 2
D. 5
Answer» B. 10
12.

What is the output of the code shown below? def f1(): x=100 print(x) x=+1 f1()

A. Error
B. 100
C. 101
D. 99
Answer» C. 101
13.

The output of the code shown below is: def f1(): x=15 print(x) x=12 f1()

A. Error
B. 12
C. 15
D. 1512
Answer» D. 1512
14.

What is the output of the following? def foo(i, x=[]): x.append(x.append(i)) return x for i in range(3): y = foo(i) print(y)

A. [[[0]], [[[0]], [1]], [[[0]], [[[0]], [1]], [2]]].
B. [[0], [[0], 1], [[0], [[0], 1], 2]].
C. [0, None, 1, None, 2, None].
D. [[[0]], [[[0]], [1]], [[[0]], [[[0]], [1]], [2]]].
Answer» D. [[[0]], [[[0]], [1]], [[[0]], [[[0]], [1]], [2]]].
15.

Where are the arguments received from the command line stored?

A. sys.argv
B. os.argv
C. argv
D. none of the mentioned
Answer» B. os.argv
16.

What is the output of the following code? def foo(x): x[0] = ['def'] x[1] = ['abc'] return id(x) q = ['abc', 'def'] print(id(q) == foo(q))

A. True
B. False
C. None
D. Error
Answer» B. False
17.

How are required arguments specified in the function heading?

A. identifier followed by an equal to sign and the default value
B. identifier followed by the default value within backticks (“)
C. identifier followed by the default value within square brackets ([])
D. identifier
Answer» E.
18.

How are default arguments specified in the function heading?

A. identifier followed by an equal to sign and the default value
B. identifier followed by the default value within backticks (“)
C. identifier followed by the default value within square brackets ([])
D. identifier
Answer» B. identifier followed by the default value within backticks (“)
19.

What is the value stored in sys.argv[0]?

A. null
B. you cannot access it
C. the program’s name
D. the first argument
Answer» D. the first argument
20.

What is the type of sys.argv?

A. set
B. list
C. tuple
D. string
Answer» C. tuple
21.

Which module in the python standard library parses options received from the command line?

A. getopt
B. os
C. getarg
D. main
Answer» B. os
22.

How are variable length arguments specified in the function heading?

A. one star followed by a valid identifier
B. one underscore followed by a valid identifier
C. two stars followed by a valid identifier
D. two underscores followed by a valid identifier
Answer» B. one underscore followed by a valid identifier
23.

What is the output of the following code? def foo(k): k = [1] q = [0] foo(q) print(q)

A. [0].
B. [1].
C. [1, 0].
D. [0, 1].
Answer» B. [1].
24.

What is the output of the following code? def foo(i, x=[]): x.append(i) return x for i in range(3): print(foo(i))

A. [0] [1] [2].
B. [0] [0, 1] [0, 1, 2].
C. [1] [2] [3].
D. [1] [1, 2] [1, 2, 3].
Answer» C. [1] [2] [3].
25.

What is the output of the following code? def foo(x): x = ['def', 'abc'] return id(x) q = ['abc', 'def'] print(id(q) == foo(q))

A. True
B. False
C. None
D. Error
Answer» C. None
26.

What is the output of the following code? def foo(): total += 1 return total total = 0 print(foo())

A. 0
B. 1
C. error
D. none of the mentioned
Answer» D. none of the mentioned
27.

What is the output of the following code? def foo(): return total + 1 total = 0 print(foo())

A. 0
B. 1
C. error
D. none of the mentioned
Answer» C. error
28.

What is the output of the following code? def foo(fname, val): print(fname(val)) foo(max, [1, 2, 3]) foo(min, [1, 2, 3])

A. 3 1
B. 1 3
C. error
D. none of the mentioned
Answer» B. 1 3
29.

How many keyword arguments can be passed to a function in a single function call?

A. zero
B. one
C. zero or more
D. one or more
Answer» D. one or more
30.

How are keyword arguments specified in the function heading?

A. one star followed by a valid identifier
B. one underscore followed by a valid identifier
C. two stars followed by a valid identifier
D. two underscores followed by a valid identifier
Answer» D. two underscores followed by a valid identifier
31.

What is the output of the following code? def foo(k): k[0] = 1 q = [0] foo(q) print(q)

A. [0].
B. [1].
C. [1, 0].
D. [0, 1].
Answer» C. [1, 0].
32.

What is the length of sys.argv?

A. number of arguments
B. number of arguments + 1
C. number of arguments – 1
D. none of the mentioned
Answer» C. number of arguments – 1
33.

What is the type of each element in sys.argv?

A. set
B. list
C. tuple
D. string
Answer» E.
34.

What is the output of the following piece of 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
Answer» D. An exception is thrown
35.

What is the output of the following 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
Answer» B. zz
36.

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
Answer» D. An exception is thrown without the return statement
37.

What is the output of the following code? def change(one, *two): print(type(two)) change(1,2,3,4)

A. Integer
B. Tuple
C. Dictionary
D. An exception is thrown
Answer» C. Dictionary
38.

What is the output of the following code? def change(i = 1, j = 2): i = i + j j = j + 1 print(i, j) change(j = 1, i = 2)

A. An exception is thrown because of conflicting values
B. 1 2
C. 3 3
D. 3 2
Answer» E.
39.

What is the output of the following code? a=10 b=20 def change(): global b a=45 b=56 change() print(a) print(b)

A. 10 56
B. 45 56
C. 10 20
D. Syntax Error
Answer» B. 45 56
40.

What is the output of the following piece of 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
Answer» C. 1
41.

What is the output of the following 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
Answer» D. An exception is thrown
42.

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
Answer» D. An automatic variable
43.

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
Answer» C. A local variable
44.

What is the output of this program? L = [lambda x: x ** 2, lambda x: x ** 3, lambda x: x ** 4] for f in L: print(f(3))

A. 27 81 343
B. 6 9 12
C. 9 27 81
D. None of the mentioned
Answer» D. None of the mentioned
45.

What is the output of below program? def writer(): title = 'Sir' name = (lambda x:title + ' ' + x) return name who = writer() who('Arthur')

A. Arthur Sir
B. Sir Arthur
C. Arthur
D. None of the mentioned
Answer» C. Arthur
46.

What is the output of below program? def f(x, y, z): return x + y + z f(2, 30, 400)

A. 432
B. 24000
C. 430
D. No output
Answer» B. 24000
47.

What is the output of below program? lamb = lambda x: x ** 3 print(lamb(5))

A. 15
B. 555
C. 125
D. None of the mentioned
Answer» D. None of the mentioned
48.

What is the output of this program? y = 6 z = lambda x: x * y print z(8)

A. 48
B. 14
C. 64
D. None of the mentioned
Answer» B. 14
49.

Python supports the creation of anonymous functions at runtime, using a construct called __________

A. Lambda
B. pi
C. anonymous
D. None of the mentioned
Answer» B. pi
50.

What is the output of the below program? def sum(*args): '''Function returns the sum of all values''' r = 0 for i in args: r += i return r print sum.__doc__ print sum(1, 2, 3) print sum(1, 2, 3, 4, 5)

A. 6 15
B. 6 100
C. 123 12345
D. None of the mentioned
Answer» B. 6 100