Python — Quiz

Python MCQ

66 questions · Test your knowledge

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