Python — Learn

Python MCQ

Review each question and reveal answers to strengthen your understanding

1 What is answer of this expression, 22 % 3 is?
✅ Correct Answer: 2
2 What is the output of this expression, 3*1**3?
✅ Correct Answer: 3
3 Which of the following will run without errors ?
✅ Correct Answer: 1
4 What dataype is the object below ? L = [1, 23, 'hello', 1].
✅ Correct Answer: 1
5 What does --------- 5 evaluate to?
✅ Correct Answer: 1
6 What is the result of round(0.5) “ round(-0.5)?
✅ Correct Answer: 2
7 What is the maximum possible length of an identifier?
✅ Correct Answer: 4
8 All keywords in Python are in
✅ Correct Answer: 4
9 Which of the following is an invalid statement?
✅ Correct Answer: 2
10 Which of these in not a core datatype?
✅ Correct Answer: 4
11 The output of the two codes shown below is the same. State whether this statement is true or false. bin((2**16)-1) '{}'.format(bin((2**16)-1))
✅ Correct Answer: 1
12 What is the output of the code shown below? 'The {} side {1} {2}'.format('bright', 'of', 'life')
✅ Correct Answer: 1
13 In the code shown below, which function is the decorator? def mk(x): def mk1(): print("Decorated") x() return mk1 def mk2(): print("Ordinary") p = mk(mk2) p()
✅ Correct Answer: 2
14 What is the output of the code shown below? def f(x): def f1(a, b): print("hello") if b==0: print("NO") return return f(a, b) return f1 @f def f(a, b): return a%b f(4,0)
✅ Correct Answer: 1
15 What is the output of the code shown below? def mk(x): def mk1(): print("Decorated") x() return mk1 def mk2(): print("Ordinary") p = mk(mk2) p()
✅ Correct Answer: 4
16 What is the result of the expression shown below if x=56.236? print("%.2f"%x)
✅ Correct Answer: 2
17 h of the following formatting options can be used in order to add 'n' blank spaces after a given string 'S'?
✅ Correct Answer: 2
18 What is the output of the code shown? x=3.3456789 '%f | %e | %g' %(x, x, x)
✅ Correct Answer: 4
19 The output of the code shown below is: s='{0}, {1}, and {2}' s.format('hello', 'good', 'morning')
✅ Correct Answer: 3
20 What is the output of the code shown below? def d(f): def n(*args): return '$' + str(f(*args)) return n @d def p(a, t): return a + a*t print(p(100,0))
✅ Correct Answer: 2
21 What is the output when following code is executed ? print r" hello" The output is
✅ Correct Answer: 2
22 What is the output of the following code ? example = "snow world" example[3] = 's' print example
✅ Correct Answer: 3
23 What is the output of "hello+1+2+3 ?
✅ Correct Answer: 3
24 What is the output of the following? print('*', "abcdef".center(7), '*')
✅ Correct Answer: 2
25 What is the output of the following? print("xyyzxyzxzxyy".count('xyy', 2, 11))
✅ Correct Answer: 2
26 What is the output of the following? print("Hello {1} and {0}".format('bin', 'foo'))
✅ Correct Answer: 1
27 What is the output of the following? print('The sum of {0} and {1} is {2}'.format(2, 10, 12))
✅ Correct Answer: 1
28 What is the output of the following? print('ab'.isalpha())
✅ Correct Answer: 1
29 What is the output of the following? print('1.1'.isnumeric())
✅ Correct Answer: 2
30 What is the output of the following? print('a'.maketrans('ABC', '123'))
✅ Correct Answer: 1
31 What is the output of the following? print('xyyxyyxyxyxxy'.replace('xy', '12', 100))
✅ Correct Answer: 2
32 . What is the output of the following? print('abcd'.translate({'a': '1', 'b': '2', 'c': '3', 'd': '4'}))
✅ Correct Answer: 1
33 What is the output of the following piece of code when executed in the python shell? a={1,2,3} a.intersection_update({2,3,4,5}) a
✅ Correct Answer: 2
34 Which of the following lines of code will result in an error?
✅ Correct Answer: 4
35 What is the output of the code shown below? s=set([1, 2, 3]) s.union([4, 5]) s|([4, 5])
✅ Correct Answer: 3
36 What is the output of the line of code shown below, if s1= {1, 2, 3}? s1.issubset(s1)
✅ Correct Answer: 1
37 What will be the output? d = {"john":40, "peter":45} d["john"]
✅ Correct Answer: 1
38 What is the output of the following piece of code when executed in Python shell? a=("Check")*3 a
✅ Correct Answer: 3
39 Is the following piece of code valid? a=2,3,4,5 a
✅ Correct Answer: 4
40 What is the output of the following code? a,b=6,7 a,b=b,a a,b
✅ Correct Answer: 3
41 How many keyword arguments can be passed to a function in a single function call?
✅ Correct Answer: 3
42 What is the output of the code shown below? def f1(): x=100 print(x) x=+1 f1() A.
✅ Correct Answer: 2
43 On assigning a value to a variable inside a function, it automatically becomes a global variable. State whether true or false.
✅ Correct Answer: 2
44 . Which of these is false about recursion?
✅ Correct Answer: 3
45 What is the output of the code shown below? l1=[1, 2, 3, [4]] l2=list(l1) id(l1)==id(l2)
✅ Correct Answer: 2
46 What are the methods which begin and end with two underscore characters called?
✅ Correct Answer: 1
47 What is the output of the code shown below? def f(x): yield x+1 print("test") yield x+2 g=f(9)
✅ Correct Answer: 4
48 The output of the code shown below is: int('65.43')
✅ Correct Answer: 2
49 What is the output of the following piece of code? class A(): def disp(self): print("A disp()") class B(A): pass obj = B() obj.disp()
✅ Correct Answer: 4
50 What is the output of the following piece of code? class Demo: def __init__(self): self.x = 1 def change(self): self.x = 10 class Demo_derived(Demo): def change(self): self.x=self.x+1 return self.x def main(): obj = Demo_derived() print(obj.change()) main()
✅ Correct Answer: 4
51 What is the result of the expression if x=15 and y=12:
✅ Correct Answer: 3
52 What is the value of this expression: bin(10-2)+bin(12^4)
✅ Correct Answer: 4
53 What is the two's complement of -44?
✅ Correct Answer: 2
54 What is the output of the code shown below? not(3>4) not(1&1)
✅ Correct Answer: 2
55 What is the output of the code shown below? class Truth: pass x=Truth() bool(x)
✅ Correct Answer: 2
56 What is the value of x if: x = int(43.55+2/2)
✅ Correct Answer: 2
57 What is the value of the expression: 4+2**5//10
✅ Correct Answer: 2
58 What is the value of the following expression: 24//6%3, 24//4//2
✅ Correct Answer: 1
59 What is the output of the following? i = 2 while True: if i%3 == 0: break print(i) i += 2
✅ Correct Answer: 2
60 What is the output of the following? x = "abcdef" i = "i" while i in x: print(i, end=" ")
✅ Correct Answer: 1
61 What is the output of the following? x = 'abcd' for i in x: print(i.upper())
✅ Correct Answer: 2
62 What is the output of the following? x = 'abcd' for i in range(len(x)): x[i].upper() print (x)
✅ Correct Answer: 1
63 What is the output of the following? d = {0: 'a', 1: 'b', 2: 'c'} for x in d.values(): print(x)
✅ Correct Answer: 2
64 . What is the output of the following? for i in range(float('inf')): print (i)
✅ Correct Answer: 4
65 What is the output of the following? string = "my name is x" for i in string.split(): print (i, end=", ")
✅ Correct Answer: 3
66 What is the output of the following? a = [0, 1, 2, 3] for a[0] in a: print(a[0])
✅ Correct Answer: 1
Back to All Quizzes