aSportZone
Home
MCQs
Python — Quiz
Python MCQ
66 questions · Test your knowledge
Home
/
MCQs
/
Python MCQ
1
What is answer of this expression, 22 % 3 is?
A
7
B
1
C
0
D
5
2
What is the output of this expression, 3*1**3?
A
27
B
9
C
3
D
1
3
Which of the following will run without errors ?
A
round(45.8)
B
round(6352.898,2,5)
C
round()
D
round(7463.123,2,1)
4
What dataype is the object below ? L = [1, 23, 'hello', 1].
A
list
B
dictionary
C
array
D
tuple
5
What does --------- 5 evaluate to?
A
+5
B
-11
C
+11
D
-5
6
What is the result of round(0.5) “ round(-0.5)?
A
1.0
B
2.0
C
0.0
D
None of the mentioned
7
What is the maximum possible length of an identifier?
A
31 characters
B
63 characters
C
79 characters
D
none of the mentioned
8
All keywords in Python are in
A
lower case
B
UPPER CASE
C
Capitalized
D
None of the mentioned
9
Which of the following is an invalid statement?
A
abc = 1,000,000
B
a b c = 1000 2000 3000
C
a,b,c = 1000, 2000, 3000
D
a_b_c = 1,000,000
10
Which of these in not a core datatype?
A
Lists
B
Dictionary
C
Tuples
D
Class
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))
A
True
B
False
C
Both I and II
D
Only I
12
What is the output of the code shown below? 'The {} side {1} {2}'.format('bright', 'of', 'life')
A
Error
B
'The bright side of life
C
The {bright} side {of} {life}
D
No output
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()
A
p()
B
mk1()
C
mk1()
D
mk2()
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)
A
helloNO
B
helloZero Division Error
C
NO
D
hello
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()
A
DecoratedDecorated
B
OrdinaryOrdinary
C
OrdinaryDecorated
D
DecoratedOrdinary
16
What is the result of the expression shown below if x=56.236? print("%.2f"%x)
A
56.00
B
56.24
C
. 56.23
D
0056.236
17
h of the following formatting options can be used in order to add 'n' blank spaces after a given string 'S'?
A
print(-ns"Â%S)
B
print(-ns"Â%S)
C
print(%ns"Â%S)
D
print(%-ns"Â%S)
18
What is the output of the code shown? x=3.3456789 '%f | %e | %g' %(x, x, x)
A
Error
B
'3.3456789 | 3.3456789+00 | 3.345678
C
'3.345678 | 3.345678e+0 | 3.345678'
D
'3.345679 | 3.345679e+00 | 3.34568'
19
The output of the code shown below is: s='{0}, {1}, and {2}' s.format('hello', 'good', 'morning')
A
hello good and morning'
B
'hello, good, morning
C
'hello, good, and morning'
D
Error
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))
A
100
B
$100
C
$0
D
0
21
What is the output when following code is executed ? print r" hello" The output is
A
a new line and hello
B
hello
C
the letter r and then hello
D
Error
22
What is the output of the following code ? example = "snow world" example[3] = 's' print example
A
snow
B
snow world
C
Error
D
snos world
23
What is the output of "helloÂ+1+2+3 ?
A
hello123
B
hello
C
Error
D
hello6
24
What is the output of the following? print('*', "abcdef".center(7), '*')
A
* abcdef *
B
* abcdef *
C
*abcdef *
D
* abcdef*
25
What is the output of the following? print("xyyzxyzxzxyy".count('xyy', 2, 11))
A
2
B
0
C
1
D
Error
26
What is the output of the following? print("Hello {1} and {0}".format('bin', 'foo'))
A
Hello foo and bin
B
Hello bin and foo
C
Error
D
None of the mentioned
27
What is the output of the following? print('The sum of {0} and {1} is {2}'.format(2, 10, 12))
A
The sum of 2 and 10 is 12
B
Error
C
The sum of 0 and 1 is 2
D
None of the mentioned
28
What is the output of the following? print('ab'.isalpha())
A
True
B
False
C
None
D
Error
29
What is the output of the following? print('1.1'.isnumeric())
A
True
B
False
C
None
D
Error
30
What is the output of the following? print('a'.maketrans('ABC', '123'))
A
{97: 49, 98: 50, 99: 51}
B
{65: 49, 66: 50, 67: 51}
C
{97: 49}
D
1
31
What is the output of the following? print('xyyxyyxyxyxxy'.replace('xy', '12', 100))
A
xyyxyyxyxyxxy
B
12y12y1212x12
C
none of the mentioned
D
Error
32
. What is the output of the following? print('abcd'.translate({'a': '1', 'b': '2', 'c': '3', 'd': '4'}))
A
abcd
B
1234
C
error
D
none of the mentioned
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
A
{2,3}
B
Error, duplicate item present in list
C
Error, no method called intersection_update for set data type
D
{1,4,5}
34
Which of the following lines of code will result in an error?
A
s={abs}
B
s={4, 'abc', (1,2)}
C
s={2, 2.2, 3, 'xyz'}
D
s={san}
35
What is the output of the code shown below? s=set([1, 2, 3]) s.union([4, 5]) s|([4, 5])
A
{1, 2, 3, 4, 5}{1, 2, 3, 4, 5}
B
Error{1, 2, 3, 4, 5}
C
{1, 2, 3, 4, 5}Error
D
ErrorError
36
What is the output of the line of code shown below, if s1= {1, 2, 3}? s1.issubset(s1)
A
True
B
Error
C
No output
D
False
37
What will be the output? d = {"john":40, "peter":45} d["john"]
A
40
B
45
C
john
D
peter"Â
38
What is the output of the following piece of code when executed in Python shell? a=("Check")*3 a
A
('Check','Check','Check')
B
Operator not valid for tuples
C
('CheckCheckCheck')
D
Syntax error
39
Is the following piece of code valid? a=2,3,4,5 a
A
Yes, 2 is printed
B
Yes, [2,3,4,5] is printed
C
No, too many values to unpack
D
Yes, (2,3,4,5) is printed
40
What is the output of the following code? a,b=6,7 a,b=b,a a,b
A
6,7)
B
Invalid syntax
C
(7,6)
D
Nothing is printed
41
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
42
What is the output of the code shown below? def f1(): x=100 print(x) x=+1 f1() A.
A
Error
B
100
C
101
D
91
43
On assigning a value to a variable inside a function, it automatically becomes a global variable. State whether true or false.
A
True
B
False
C
Error
D
Not mentioned
44
. Which of these is false about recursion?
A
Recursive function can be replaced by a non-recursive function
B
Recursive functions usually take more memory space than non-recursive function
C
Recursive functions run faster than non-recursive function
D
Recursion makes programs easier to understand
45
What is the output of the code shown below? l1=[1, 2, 3, [4]] l2=list(l1) id(l1)==id(l2)
A
True
B
False
C
Error
D
Address of l1
46
What are the methods which begin and end with two underscore characters called?
A
Special methods
B
In-built methods
C
User-defined methods
D
Additional methods
47
What is the output of the code shown below? def f(x): yield x+1 print("test") yield x+2 g=f(9)
A
Error
B
test
C
test1012
D
No output
48
The output of the code shown below is: int('65.43')
A
ImportError
B
ValueError
C
TypeError
D
NameError
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()
A
Invalid syntax for inheritance
B
Error because when object is created, argument must be passed
C
Nothing is printed
D
A 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()
A
11
B
2
C
1
D
An exception is thrown
51
What is the result of the expression if x=15 and y=12:
A
b1101
B
0b1101
C
12
D
1101
52
What is the value of this expression: bin(10-2)+bin(12^4)
A
0b10000
B
0b10001000
C
0b1000b1000
D
0b10000b1000
53
What is the two's complement of -44?
A
1011011
B
11010100
C
11101011
D
10110011
54
What is the output of the code shown below? not(3>4) not(1&1)
A
TrueTrue
B
TrueFalse
C
FalseTrue
D
FalseFalse
55
What is the output of the code shown below? class Truth: pass x=Truth() bool(x)
A
pass
B
true
C
false
D
error
56
What is the value of x if: x = int(43.55+2/2)
A
43
B
44
C
22
D
23
57
What is the value of the expression: 4+2**5//10
A
3
B
7
C
77
D
0
58
What is the value of the following expression: 24//6%3, 24//4//2
A
(1,3)
B
(0,3)
C
(1,0)
D
(3,1)
59
What is the output of the following? i = 2 while True: if i%3 == 0: break print(i) i += 2
A
i i i i i i
B
a a a a a a
C
a a a a a
D
none of the mentioned
60
What is the output of the following? x = "abcdef" i = "i" while i in x: print(i, end=" ")
A
no output
B
i i i i i i "
C
a b c d e f
D
abcdef
61
What is the output of the following? x = 'abcd' for i in x: print(i.upper())
A
a b c d
B
A B C D
C
a B C D
D
error
62
What is the output of the following? x = 'abcd' for i in range(len(x)): x[i].upper() print (x)
A
abcd
B
ABCD
C
error
D
none of the mentioned
63
What is the output of the following? d = {0: 'a', 1: 'b', 2: 'c'} for x in d.values(): print(x)
A
0 1 2
B
0 a 1 b 2 c
C
0 a 1 b 2 c
D
none of the mentioned
64
. What is the output of the following? for i in range(float('inf')): print (i)
A
0.0 0.1 0.2 0.3
B
0 1 2 3
C
0.0 1.0 2.0 3.0
D
none of the mentioned
65
What is the output of the following? string = "my name is x" for i in string.split(): print (i, end=", ")
A
m, y, , n, a, m, e, , i, s, , x,
B
m, y, , n, a, m, e, , i, s, , x
C
my, name, is,
D
error
66
What is the output of the following? a = [0, 1, 2, 3] for a[0] in a: print(a[0])
A
0 1 2 3
B
0 1 2 2
C
3 3 3 3
D
error
Submit Quiz
Back to All Quizzes