Google News
logo
Python - Quiz(MCQ)
1 .
Who is inventor of Python ?
A)
Larry Wall
B)
Mark Jukervich
C)
Guido van Rossum
D)
Dennis Ritchie

Correct Answer : Option (C) :  

Guido van Rossum

2 .
Python initial release date ?
A)
1991
B)
1992
C)
1995
D)
1996

Correct Answer : Option (A) :   1991

3 .
Which of the following statements is true?
A)
Python is a high level programming language.
B)
Python is an interpreted language.
C)
Python is an object-oriented language.
D)
All of the above.

Correct Answer : Option (D) :  

All of the above.

4 .
What symbol can you use to comment out one line of code?
A)
*
B)
#
C)
//
D)
(comment)

Correct Answer : Option (B) :  

5 .
What is the difference between a class and an object in Python?
A)
There is no difference between a class and an object
B)
Classes are made from iterations while objects are not.
C)
Objects are created from classes.
D)
Objects are not able to be called. 

Correct Answer : Option (C) :  

Objects are created from classes. 

6 .
Which of the following is not a class method?
A)
Non-static
B)
Static
C)
Bounded
D)
Unbounded

Correct Answer : Option (A) :  

Non-static 

7 .
In python which keyword is used to start function ?
A)
function
B)
def 
C)
try
D)
import

Correct Answer : Option (B) :  

def 

8 .
Which of the following environment variable for Python is an alternative module search path?
A)
PYTHONPATH
B)
PYTHONSTARTUP
C)
PYTHONCASEOK
D)
PYTHONHOME 

Correct Answer : Option (D) :  

PYTHONHOME

9 .
Which of the following functions print the output to the console?
A)
echo
B)
output
C)
print
D)
console.log

Correct Answer : Option (C) :  

print 

10 .
Which module in Python supports regular expressions?
A)
re 
B)
regex
C)
pyregex
D)
None of the above

Correct Answer : Option (A) :  

re

11 .
Which of the following keyword is a valid placeholder for body of the function ?
A)
break
B)
continue
C)
body
D)
pass 

Correct Answer : Option (D) :  

pass

12 .
Which of the following is correct?
A)
Variable name can start with an underscore.
B)
Variable name can start with a digit.
C)
Keywords cannot be used as a variable name.
D)
Variable name can have symbols like: @, #, $ etc.

Correct Answer : Option (A) :  

Variable name can start with an underscore. 

13 .
Which of the following statements is NOT true about Python?
A)
Python can be used for web development 
B)
Python’s syntax is much like PHP 
C)
Python can run on any type of platform
D)
Python can be used to generate dynamic web pages

Correct Answer : Option (B) :  

Python’s syntax is much like PHP

14 .
What is the return value of trunc() ?
A)
int
B)
bool
C)
float
D)
None of the above

Correct Answer : Option (A) :  

int 

15 .
What is the need of :
if __name__ == "__main__":
 somemethod()
A)
Create new module
B)
Define generators
C)
Run python module as main program
D)
Create new objects

Correct Answer : Option (C) :  

Run python module as main program 

16 .
Which operator is used to compare two numbers for equality?
A)
=
B)
==
C)
!=
D)
+=

Correct Answer : Option (B) :   ==

17 .
In python which is the correct method to load a module ?
A)
include math
B)
import math 
C)
#include<math.h>
D)
using math

Correct Answer : Option (B) :  

import math

18 .
Which function is used to open the file for reading in python ?
A)
fopen(filename, mode)
B)
open_file(filename, mode)
C)
openfile(filename, mode)
D)
open(filename, mode)

Correct Answer : Option (D) :  

open(filename, mode)

19 .
Which of the following function checks in a string that all characters are numeric?
A)
isnumeric() 
B)
islower()
C)
isspace()
D)
istitle()

Correct Answer : Option (A) :  

isnumeric()

20 .
In python 3 what does // operator do ?
A)
Float division
B)
Integer division
C)
returns remainder
D)
same as a**b

Correct Answer : Option (B) :  

Integer division

21 .
What is used to take input from the user in Python?
A)
cin
B)
scanf()
C)
input() 
D)
<>

Correct Answer : Option (C) :  

input() 

22 .
What is the name of data type for character in python ?
A)
chr
B)
char
C)
character
D)
python do not have any data type for characters they are treated as string. 

Correct Answer : Option (D) :  

python do not have any data type for characters they are treated as string. 

23 .
What error occurs when you execute?
apple = mango​
A)
SyntaxError
B)
NameError
C)
ValueError
D)
TypeError

Correct Answer : Option (B) :  

NameError

24 .
what should the below code print?
print type(1J)
A)
<type 'complex'>
B)
<type 'unicode'>
C)
<type 'float'>
D)
<type 'dict'>

Correct Answer : Option (A) :  

<type 'complex'>

25 .
What is the output of the following code?
import re
sentence = 'Learn Python Programming'
test = re.match(r'(.*) (.*?) (.*)', sentence)
print(test.group())
 
A)
Learn Python Programming
B)
(Learn, Python, Programming)
C)
(‘Learn’, ‘Programming’)
D)
‘Learn Python Programming’

Correct Answer : Option (A) :  

Learn Python Programming

26 .
What is the output of L[2] if L = [1,2,3]?
A)
2
B)
3
C)
4
D)
None of the above.

Correct Answer : Option (B) :  

27 .
Which of the following is a valid tuple in Python?
A)
sampleTuple = (1,2,3,4,5) 
B)
sampleTuple = {1,2,3,4,5}
C)
sampleTuple = [1,2,3,4,5]
D)
sampleTuple = /1,2,3,4,5/

Correct Answer : Option (A) :  

sampleTuple = (1,2,3,4,5)

28 .
Let a = [ 1,2,3,4,5 ] then which of the following is correct ?
A)
print(a[:]) => [1,2,3,4]
B)
print(a[0:]) => [2,3,4,5]
C)
print(a[:100]) => [1,2,3,4,5]
D)
print(a[-1:]) => [1,2]

Correct Answer : Option (C) :  

print(a[:100]) => [1,2,3,4,5]

29 .
What is the output of the following code?
print(1, 2, 3, 4, sep='*')​
A)
1 2 3 4
B)
1*2*3*4 
C)
1234
D)
24

Correct Answer : Option (B) :  

1*2*3*4

30 .
What is the output of the following code?
numbers = [2, 3, 4]
print(numbers)
A)
[2, 3, 4] 
B)
2 3 4
C)
2, 3, 4 
D)
[2 3 4]

Correct Answer : Option (A) :  

[2, 3, 4] 

31 .
What is the value of colors[2]?
colors = ['red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet']​
A)
orange
B)
yellow
C)
indigo
D)
blue

Correct Answer : Option (B) :  

yellow

32 .
What is the output of the following code?
print(3 >= 3)​
A)
True
B)
False
C)
3 >= 3
D)
None of the above

Correct Answer : Option (A) :  

True

33 .
what is the output of the following code?
print(type([1,2]))​
A)
<class 'tuple'>
B)
<class 'int'>
C)
<class 'list'>
D)
<class 'complex'>

Correct Answer : Option (C) :  

<class 'list'>

34 .
What is the output when following code is executed ?
>>> str1 = 'hello'
>>> str2 = ','
>>> str3 = 'world'
>>> str1[-1:]​
A)
olleh
B)
hello
C)
h
D)
o

Correct Answer : Option (D) :  

o

35 .
What is the output when following code is executed ?
>>>str1="helloworld"
>>>str1[::-1]
A)
dlrowolleh 
B)
hello
C)
world
D)
helloworld

Correct Answer : Option (A) :  

dlrowolleh

36 .
What will be printed:
def f(a, b):
 print(a, b)
f(b=1, *(2,))​
A)
1 2
B)
2 1
C)
This code causes TypeError
D)
None of the above

Correct Answer : Option (B) :  

2 1

37 .
What is inheritance used for?
A)
To give a class the methods and variables of an interface 
B)
To create a new object
C)
To give an interface the methods and variables of a class
D)
To give a class the variables but not the methods

Correct Answer : Option (A) :  

To give a class the methods and variables of an interface

38 .
What will be placed in a?
a = [1,2,3]
a[-3:-1] = 10,20,30,40
A)
IndexError
B)
[10, 20, 30, 40, 3]
C)
[10, 20, 30, 40, 2, 3]
D)
[10, 20, 30, 40]

Correct Answer : Option (B) :  

[10, 20, 30, 40, 3]

39 .
What does this function return?
def f(a,b):
 return a,b
f(**{'b':2,'a':1})​
A)
(1, 2)
B)
(2, 1)
C)
It causes TypeError: f() got an unexpected keyword argument
D)
All of the above

Correct Answer : Option (A) :  

(1, 2)

40 .
Which of these is not a Python datatype?
A)
int
B)
long
C)
decimal
D)
float

Correct Answer : Option (C) :  

decimal

41 .
Which is not a valid Python loop?
A)
for loop
B)
while loop
C)
Both A and B
D)
iter loop

Correct Answer : Option (D) :  

iter loop

42 .
What is a nested loop?
A)
a loop without condition
B)
a loop called from an object
C)
a loop inside a loop
D)
a recursive loop

Correct Answer : Option (B) :  

a loop called from an object

43 .
Which of the following is a valid way to start a while loop in Python?
A)
while loop a < 10
B)
while a < 10: 
C)
while(a < 10)
D)
while loop a < 10:

Correct Answer : Option (B) :  

while a < 10:

44 .
How to access list elements?
A)
print l->get(0)
B)
print l.item(0)
C)
print l(0)
D)
print l[0]

Correct Answer : Option (A) :  

print l->get(0)

45 .
What gets printed?
nums = set([1,1,2,3,3,3,4])
print(len(nums))​
A)
1
B)
2
C)
4
D)
5

Correct Answer : Option (C) :  

4

46 .
How do you create a variable “a” that is equal to 2?
A)
var a = 2
B)
int a = 2
C)
a = 2
D)
variable a = 2

Correct Answer : Option (C) :  

a = 2

47 .
Which of the following is not a valid assignment operator?
A)
+=
B)
-=
C)
*=
D)
X=

Correct Answer : Option (D) :  

X=

48 .
Which one of the following is a valid Python if statement
A)
 if a >= 22: 
B)
if (a >= 22)
C)
if (a => 22)
D)
if a >= 22

Correct Answer : Option (A) :  

 if a >= 22:

49 .
The output of the code shown below:
import time
time.asctime()
A)
Current date only
B)
UTC time
C)
Current date and time 
D)
Current time only

Correct Answer : Option (C) :  

Current date and time

50 .
Which of the following is a valid way to start a function in Python?
A)
def someFunction(): 
B)
function someFunction()
C)
def someFunction()
D)
function someFunction():

Correct Answer : Option (A) :  

def someFunction():

51 .
Which of the following functions clears the regular expression cache?
A)
re.sub()
B)
re.pos()
C)
re.subn()
D)
re.purge()

Correct Answer : Option (D) :  

re.purge()

52 .
Which of the following is a valid dictionary in Python?
A)
myExample = {‘someItem’=>2, ‘otherItem’=>20}
B)
myExample = {‘someItem’: 2, ‘otherItem’: 20} 
C)
myExample = (‘someItem’=>2, ‘otherItem’=>20)
D)
myExample = (‘someItem’: 2, ‘otherItem’: 20)

Correct Answer : Option (B) :  

myExample = {‘someItem’: 2, ‘otherItem’: 20}

53 .
What is the proper way to open a file that you intend to read from?
A)
f = open(“test.txt”, “read”)
B)
f = open(“r”,”test.txt”)
C)
f = open(“test.txt”, “r”) 
D)
f = open(“read”,”test.txt”)

Correct Answer : Option (C) :  

f = open(“test.txt”, “r”)

54 .
Which of the following lines of code will not show a match?
A)
>>> re.match(‘ab*’, ‘a’)
B)
>>> re.match(‘ab*’, ‘ab’)
C)
>>> re.match(‘ab*’, ‘abb’)
D)
>>> re.match(‘ab*’, ‘ba’) 

Correct Answer : Option (D) :  

>>> re.match(‘ab*’, ‘ba’)

55 .
What is the output of the snippet of code shown below?
import turtle
t=turtle.Pen
t.tilt(75)
t.forward(100)​
A)
A straight line of 100 units tiled at 75 degrees from the horizontal
B)
A straight line of 100 units tilted at 15 degrees from the horizontal
C)
A straight line of 100 units lying along the horizontal
D)
None of the above 

Correct Answer : Option (C) :  

A straight line of 100 units lying along the horizontal

56 .
What is the output of the following code?
str = "freetime"
print (str[1:3])
A)
fr
B)
re
C)
fre
D)
ree

Correct Answer : Option (B) :   re

57 .
Is Python case sensitive when dealing with identifiers?
A)
yes
B)
no
C)
machine dependent
D)
none of the mentioned

Correct Answer : Option (A) :   yes

58 .
Which of these in not a core data type?
A)
Lists
B)
Dictionary
C)
Tuples
D)
Class

Correct Answer : Option (D) :   Class


Explanation : Class is a user defined data type.

59 .
What is the maximum possible length of an identifier?
A)
31 characters
B)
60 characters
C)
73 characters
D)
none of the mentioned

Correct Answer : Option (D) :   none of the mentioned

60 .
Which of the following is invalid?
A)
_a = 1
B)
__a = 1
C)
__str__ = 1
D)
none of the mentioned

Correct Answer : Option (D) :   none of the mentioned


Explanation : All the statements will execute successfully but at the cost of reduced readability.

61 .
Which one of these is floor division?
A)
/
B)
//
C)
%
D)
None of the mentioned

Correct Answer : Option (B) :   //

62 .
What is the output of print 0.1 + 0.2 == 0.3?
A)
True
B)
False
C)
Machine dependent
D)
Error

Correct Answer : Option (B) :   False

63 .
Which of the following is not a complex number?
A)
k = 2 + 3j
B)
k = complex(2, 3)
C)
k = 2 + 3l
D)
k = 2 + 3J

Correct Answer : Option (C) :   k = 2 + 3l

64 .
What is the answer to this expression, 22 % 3 is?
A)
7
B)
0
C)
1
D)
5

Correct Answer : Option (C) :   1

65 .
What is the type of inf?
A)
Boolean
B)
Integer
C)
Float
D)
Complex

Correct Answer : Option (C) :   Float

66 .
Operators with the same precedence are evaluated in which manner?
A)
Left to Right
B)
Right to Left
C)
Can’t say
D)
None of the mentioned

Correct Answer : Option (A) :   Left to Right

67 .
What does ~4 evaluate to?
A)
-5
B)
-3
C)
-4
D)
-2

Correct Answer : Option (A) :   -5

68 .
What is the output of this expression, 3*1**3?
A)
1
B)
3
C)
9
D)
27

Correct Answer : Option (B) :   3


Explanation : First this expression will solve 1**3 because exponential has higher precedence than multiplication, so 1**3 = 1 and 3*1 = 3. Final answer is 3.

69 .
What does ~~~~~~5 evaluate to?
A)
+5
B)
+11
C)
-11
D)
-5

Correct Answer : Option (A) :   +5


Explanation : ~x is equivalent to -(x+1)

70 .
Which one of the following has the highest precedence in the expression?
A)
Exponential
B)
Addition
C)
Parentheses
D)
Multiplication

Correct Answer : Option (C) :  

Parentheses

71 .
Which of the following is incorrect?
A)
float(‘nan’)
B)
float(’12+34′)
C)
float(’56’+’78’)
D)
float(‘inf’)

Correct Answer : Option (B) :   float(’12+34′)


Explanation : ‘+’ cannot be converted to a float.

72 .
Which of the following has more precedance?
A)
/
B)
+
C)
()
D)
-

Correct Answer : Option (C) :   ()

73 .
What will be the output of 7^10 in python?
A)
02
B)
13
C)
15
D)
None of the above

Correct Answer : Option (B) :   13

74 .
Which of the following is the use of id() function in python?
A)
Id returns the identity of the object
B)
Every object doesn’t have a unique id
C)
All of the mentioned
D)
None of the above

Correct Answer : Option (A) :   Id returns the identity of the object

75 .
What will be the value of the following Python expression?
 
4 + 3 % 5
A)
0
B)
2
C)
4
D)
7

Correct Answer : Option (D) :   7

76 .
Which of the following operators has its associativity from right to left?
A)
+
B)
//
C)
**
D)
%

Correct Answer : Option (C) :   **

77 .
What will be the value of x in the following Python expression?
 
x = int(43.55+2/2)
A)
43
B)
44
C)
22
D)
23

Correct Answer : Option (B) :   44

78 .
What are the values of the following Python expressions?
 2**(3**2)
 (2**3)**2
 2**3**2
A)
64, 512, 64
B)
64, 64, 64
C)
512, 512, 512
D)
512, 64, 512

Correct Answer : Option (D) :   512, 64, 512

79 .
What is the value of the following expression?
 
8/4/2, 8/(4/2)
A)
(1.0, 4.0)
B)
(1.0, 1.0)
C)
(4.0. 1.0)
D)
(4.0, 4.0)

Correct Answer : Option (A) :   (1.0, 4.0)

80 .
What will be the output of the following Python code snippet?
 
X=”hi”
print(“05d”%X)
A)
000hi
B)
hi000
C)
00000hi
D)
error

Correct Answer : Option (D) :   error

81 .
Which 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)

Correct Answer : Option (A) :   print(“%-ns”%S)

82 .
What will be the output of the following Python code?
 
l=list('HELLO')
'first={0[0]}, third={0[2]}'.format(l)
A)
‘first=H, third=L’
B)
‘first=0, third=2’
C)
‘first=0, third=L’
D)
Error

Correct Answer : Option (A) :   ‘first=H, third=L’

83 .
What will be the output of the following Python code?
 
l=list('HELLO')
p=l[0], l[-1], l[1:3]
'a={0}, b={1}, c={2}'.format(*p)
A)
“a=’H’, b=’O’, c=(E, L)”
B)
“a=H, b=O, c=[‘E’, ‘L’]”
C)
Error
D)
Junk value

Correct Answer : Option (B) :   “a=H, b=O, c=[‘E’, ‘L’]”

84 .
What will be the output of the following Python code?
 
hex(255), int('FF', 16), 0xFF
A)
Error
B)
[0xFF, 255, 16, 255]
C)
(‘0xff’, 155, 16, 255)
D)
(‘0xff’, 255, 255)

Correct Answer : Option (D) :   (‘0xff’, 255, 255)

85 .
What will be the output of the following Python code?
 
'{a}{b}{a}'.format(a='hello', b='world')
A)
‘hello world’
B)
‘hello’ ‘world’ ‘hello’
C)
‘helloworldhello’
D)
‘hello’ ‘hello’ ‘world’

Correct Answer : Option (C) :   ‘helloworldhello’

86 .
What will be the output of the following Python code?
 
'The {} side {1} {2}'.format('bright', 'of', 'life')
A)
‘The bright side of life’
B)
‘The {bright} side {of} {life}’
C)
No output
D)
Error

Correct Answer : Option (D) :   Error

87 .
What will be the output of the following two codes?
 
i. '{0}'.format(4.56)
ii. '{0}'.format([4.56,])
A)
‘4.56’, ‘4.56,’
B)
‘4.56’, ‘[4.56]’
C)
4.56, [4.56,]
D)
4.56, [4.56,]

Correct Answer : Option (B) :   ‘4.56’, ‘[4.56]’

88 .
The output of which of the codes shown below will be: “There are 4 blue birds.”?
A)
‘There are %d %s birds.’ %(4, blue)
B)
‘There are %g %d birds.’ %4 %blue
C)
‘There are %d %s birds.’ 4, blue
D)
‘There are %s %d birds.’ %[4, blue]

Correct Answer : Option (A) :   ‘There are %d %s birds.’ %(4, blue)

89 .
What will be the output of the following Python code snippet?
 
x=3.3456789
'%f | %e | %g' %(x, x, x)
A)
‘3.345679 | 3.345679e+00 | 3.34568’
B)
‘3.345678 | 3.345678e+0 | 3.345678’
C)
‘3.3456789 | 3.3456789+00 | 3.345678’
D)
Error

Correct Answer : Option (A) :   ‘3.345679 | 3.345679e+00 | 3.34568’

90 .
What will be the output of the following Python code snippet?
 
a='hello'
q=10
vars()
A)
{‘a’ : ‘hello’, ‘q’ : 10}
B)
{‘a’ : ‘hello’, ‘q’ : 10, ……..plus built-in names set by Python….}
C)
{……Built in names set by Python……}
D)
Error

Correct Answer : Option (B) :   {‘a’ : ‘hello’, ‘q’ : 10, ……..plus built-in names set by Python….}

91 .
What will be the output of the following Python code?
 
'%x %d' %(255, 255)
A)
Error
B)
‘15f, 15f’
C)
‘255, 255’
D)
‘ff, 255’

Correct Answer : Option (D) :   ‘ff, 255’

92 .
What will be the output of the following Python statement?
 
>>>"a"+"bc"
 
A)
a
B)
bc
C)
bca
D)
abc

Correct Answer : Option (D) :   abc

93 .
What will be the output of the following Python code?
 
>>>str1="helloworld"
>>>str1[::-1]
A)
hello
B)
world
C)
dlrowolleh
D)
helloworld

Correct Answer : Option (C) :   dlrowolleh

94 .
What will be the output of the following Python code?
 
class father:
    def __init__(self, param):
        self.o1 = param
 
class child(father):
    def __init__(self, param):
        self.o2 = param
 
>>>obj = child(22)
>>>print "%d %d" % (obj.o1, obj.o2)
A)
None 22
B)
22 None
C)
None None
D)
Error is generated

Correct Answer : Option (D) :   Error is generated

95 .
What will be the output of the following Python code?
 
>>>example = "snow world"
>>>print("%s" % example[4:7])
A)
wo
B)
world
C)
sn
D)
rl

Correct Answer : Option (A) :   wo

96 .
What will be the output of the following Python code?
 
>>>example = "helle"
>>>example.find("e")
A)
-1
B)
1
C)
0
D)
Error

Correct Answer : Option (B) :   1

97 .
What will be the output of the following Python code?
 
>>>example="helloworld"
>>>example[::-1].startswith("d")
A)
True
B)
-1
C)
dlrowolleh
D)
None of the above

Correct Answer : Option (A) :   True

98 .
To concatenate two strings to a third what statements are applicable?
A)
s3 = s1 . s2
B)
s3 = s1.add(s2)
C)
s3 = s1.__add__(s2)
D)
s3 = s1 * s2

Correct Answer : Option (C) :   s3 = s1.__add__(s2)

99 .
To retrieve the character at index 3 from string s=”Hello” what command do we execute (multiple answers allowed)?
A)
s[]
B)
s.getitem(3)
C)
s.getItem(3)
D)
s.__getitem__(3)

Correct Answer : Option (D) :   s.__getitem__(3)

100 .
o check whether string s1 contains another string s2, use ________
A)
s2 in s1
B)
s1.__contains__(s2)
C)
si.in(s2)
D)
s1.contains(s2)

Correct Answer : Option (B) :   s1.__contains__(s2)

101 .
What will be the output of the following Python code?
 
class Count:
    def __init__(self, count = 0):
       self.__count = count
 
c1 = Count(2)
c2 = Count(2)
print(id(c1) == id(c2), end = " ")
 
s1 = "Good"
s2 = "Good"
print(id(s1) == id(s2))
A)
True True
B)
False False
C)
True False
D)
False True

Correct Answer : Option (D) :   False True

102 .
What function do you use to read a string?
A)
input(“Enter a string”)
B)
enter(“Enter a string”)
C)
eval(input(“Enter a string”))
D)
eval(enter(“Enter a string”))

Correct Answer : Option (A) :   input(“Enter a string”)

103 .
What will be the output of the following Python code?
 
print("Hello {name1} and {name2}".format(name1='foo', name2='bin'))
A)
Hello foo and bin
B)
Hello and
C)
Hello {name1} and {name2}
D)
Error

Correct Answer : Option (A) :   Hello foo and bin

104 .
What will be the output of the following Python code?
 
print("Hello {0[0]} and {0[1]}".format(('foo', 'bin')))
A)
Error
B)
Hello foo and bin
C)
Hello (‘foo’, ‘bin’) and (‘foo’, ‘bin’)
D)
None of the above

Correct Answer : Option (B) :   Hello foo and bin

105 .
What will be the output of the following Python code snippet?
 
print('{:,}'.format(1112223334))
A)
1112223334
B)
111,222,333,4
C)
1,112,223,334
D)
Error

Correct Answer : Option (C) :   1,112,223,334

106 .
What will be the output of the following Python code?
 
print('{0:.2%}'.format(1/3))
A)
0.33
B)
0.33%
C)
33%
D)
33.33%

Correct Answer : Option (D) :   33.33%

107 .
What will be the output of the following Python code?
 
print('a B'.isalpha())
A)
True
B)
False
C)
None
D)
Error

Correct Answer : Option (B) :   False

108 .
What will be the output of the following Python code snippet?
 
print('my_string'.isidentifier())
A)
True
B)
False
C)
None
D)
Error

Correct Answer : Option (A) :   True

109 .
What will be the output of the following Python code snippet?
 
print('cd'.partition('cd'))
A)
(”)
B)
(‘cd’)
C)
(‘cd’, ”, ”)
D)
(”, ‘cd’, ”)

Correct Answer : Option (D) :   (”, ‘cd’, ”)

110 .
What will be the output of the following Python code snippet?
 
print('abcdef12'.replace('cd', '12'))
A)
ab12ef12
B)
abcdef12
C)
ab12efcd
D)
None of the above

Correct Answer : Option (A) :   ab12ef12

111 .
What will be the output of the following Python code snippet?
 
print('abcdefcdghcd'.split('cd'))
A)
[‘ab’, ‘ef’, ‘gh’]
B)
[‘ab’, ‘ef’, ‘gh’, ”]
C)
(‘ab’, ‘ef’, ‘gh’)
D)
(‘ab’, ‘ef’, ‘gh’, ”)

Correct Answer : Option (B) :   [‘ab’, ‘ef’, ‘gh’, ”]

112 .
Which of the following commands will create a list?
A)
 list1 = []
B)
 list1 = list()
C)
list1 = list([1, 2, 3])
D)
all of the mentioned

Correct Answer : Option (D) :   all of the mentioned

113 .
Suppose list1 is [2445,133,12454,123], what is max(list1)?
A)
12454
B)
2445
C)
123
D)
133

Correct Answer : Option (A) :   12454

114 .
To shuffle the list(say list1) what function do we use?
A)
shuffle(list1)
B)
list1.shuffle()
C)
random.shuffle(list1)
D)
random.shuffleList(list1)

Correct Answer : Option (C) :   random.shuffle(list1)

115 .
Suppose list1 is [2, 33, 222, 14, 25], What is list1[:-1]?
A)
25
B)
[2, 33, 222, 14]
C)
[25, 14, 222, 33, 2]
D)
Error

Correct Answer : Option (B) :   [2, 33, 222, 14]

116 .
Suppose list1 = [0.5 * x for x in range(0, 4)], list1 is:
A)
[0, 1, 2, 3]
B)
[0, 1, 2, 3, 4]
C)
[0.0, 0.5, 1.0, 1.5]
D)
[0.0, 0.5, 1.0, 1.5, 2.0]

Correct Answer : Option (C) :   [0.0, 0.5, 1.0, 1.5]

117 .
What will be the output of the following Python code?
 
>>>list1 = [11, 2, 23]
>>>list2 = [11, 2, 2]
>>>list1 < list2 is
A)
True
B)
False
C)
Error
D)
None of the above

Correct Answer : Option (B) :   False

118 .
To remove string “hello” from list1, we use which command?
A)
list1.remove(“hello”)
B)
list1.remove(hello)
C)
list1.removeAll(“hello”)
D)
list1.removeOne(“hello”)

Correct Answer : Option (A) :   list1.remove(“hello”)

119 .
Suppose list1 is [3, 4, 5, 20, 5, 25, 1, 3], what is list1.count(5)?
A)
0
B)
1
C)
2
D)
3

Correct Answer : Option (C) :   2

120 .
Suppose listExample is [3, 4, 5, 20, 5, 25, 1, 3], what is list1 after listExample.extend([34, 5])?
A)
[3, 4, 5, 20, 5, 25, 1, 3, 34, 5]
B)
[1, 3, 3, 4, 5, 5, 20, 25, 34, 5]
C)
[1, 3, 4, 5, 20, 5, 25, 3, 34, 5]
D)
[25, 20, 5, 5, 4, 3, 3, 1, 34, 5]

Correct Answer : Option (A) :   [3, 4, 5, 20, 5, 25, 1, 3, 34, 5]

121 .
What will be the output of the following Python code?
 
>>>"Welcome to Python".split()
A)
[“Welcome”, “to”, “Python”]
B)
(“Welcome”, “to”, “Python”)
C)
{“Welcome”, “to”, “Python”}
D)
“Welcome”, “to”, “Python”

Correct Answer : Option (A) :   [“Welcome”, “to”, “Python”]

122 .
What will be the output of the following Python code?
 
myList = [1, 5, 5, 5, 5, 1]
max = myList[0]
indexOfMax = 0
for i in range(1, len(myList)):
    if myList[i] > max:
        max = myList[i]
        indexOfMax = i
 
>>>print(indexOfMax)
A)
1
B)
2
C)
3
D)
4

Correct Answer : Option (A) :   1

123 .
What will be the output of the following Python code?
 
myList = [1, 2, 3, 4, 5, 6]
for i in range(1, 6):
    myList[i - 1] = myList[i]
 
for i in range(0, 6): 
    print(myList[i], end = " ")
A)
1 1 2 3 4 5
B)
2 3 4 5 6 1
C)
2 3 4 5 6 6
D)
6 1 2 3 4 5

Correct Answer : Option (C) :   2 3 4 5 6 6

124 .
What will be the output of the following Python code?
 
def f(values):
    values[0] = 44
 
v = [1, 2, 3]
f(v)
print(v)
A)
[1, 44]
B)
[1, 2, 3]
C)
[1, 2, 3, 44]
D)
[44, 2, 3]

Correct Answer : Option (D) :   [44, 2, 3]

125 .
What will be the output of the following Python code?
 
>>>m = [[x, x + 1, x + 2] for x in range(0, 3)]
A)
[[1, 2, 3], [4, 5, 6], [7, 8, 9]]
B)
[[0, 1, 2], [1, 2, 3], [2, 3, 4]]
C)
[1, 2, 3, 4, 5, 6, 7, 8, 9]
D)
[0, 1, 2, 1, 2, 3, 2, 3, 4]

Correct Answer : Option (B) :   [[0, 1, 2], [1, 2, 3], [2, 3, 4]]

126 .
What will be the output of the following Python code?
 
values = [[3, 4, 5, 1], [33, 6, 1, 2]]
v = values[0][0]
for row in range(0, len(values)):
    for column in range(0, len(values[row])):
        if v < values[row][column]:
            v = values[row][column]
 
print(v)
 
A)
3
B)
5
C)
6
D)
33

Correct Answer : Option (D) :   33

127 .
What will be the output of the following Python code?
 
values = [[3, 4, 5, 1 ], [33, 6, 1, 2]]
 
for row in values:
    row.sort()
    for element in row:
        print(element, end = " ")
    print()
A)
The program prints on row 3 4 5 1 33 6 1 2
B)
The program prints two rows 3 4 5 1 followed by 33 6 1 2
C)
The program prints two rows 3 4 5 1 followed by 33 6 1 2
D)
The program prints two rows 1 3 4 5 followed by 1 2 6 33

Correct Answer : Option (D) :   The program prints two rows 1 3 4 5 followed by 1 2 6 33

128 .
What will be the output of the following Python code?
 
def m(list):
    v = list[0]
    for e in list:
      if v < e: v = e
    return v
 
values = [[3, 4, 5, 1], [33, 6, 1, 2]]
 
for row in values: 
    print(m(row), end = " ")
A)
1 1
B)
5 6
C)
3 33
D)
5 33

Correct Answer : Option (D) :   5 33

129 .
What will be the output of the following Python code?
 
data = [[[1, 2], [3, 4]], [[5, 6], [7, 8]]]
 
def ttt(m):
    v = m[0][0]
 
    for row in m:
        for element in row:
           if v < element: v = element
 
    return v
 
print(ttt(data[0]))
A)
1
B)
2
C)
4
D)
5

Correct Answer : Option (C) :   4

130 .
What will be the output of the following Python code snippet?
 
k = [print(i) for i in my_string if i not in "aeiou"]
A)
prints all the vowels in my_string
B)
prints all characters of my_string that aren’t vowels
C)
prints only on executing print(k)
D)
prints all the consonants in my_string

Correct Answer : Option (B) :   prints all characters of my_string that aren’t vowels

131 .
What will be the output of the following Python code snippet?
 
my_string = "hello world"
k = [(i.upper(), len(i)) for i in my_string]
print(k)
A)
[(‘H’, 1), (‘E’, 1), (‘L’, 1), (‘L’, 1), (‘O’, 1), (‘ ‘, 1), (‘W’, 1), (‘O’, 1), (‘R’, 1), (‘L’, 1), (‘D’, 1)]
B)
[(‘HELLO’, 5), (‘WORLD’, 5)]
C)
[(‘HELLO WORLD’, 11)]
D)
None of the above

Correct Answer : Option (A) :   [(‘H’, 1), (‘E’, 1), (‘L’, 1), (‘L’, 1), (‘O’, 1), (‘ ‘, 1), (‘W’, 1), (‘O’, 1), (‘R’, 1), (‘L’, 1), (‘D’, 1)]

132 .
What will be the output of the following Python code snippet?
 
x = [i**+1 for i in range(3)]; print(x);
A)
[1, 2, 5]
B)
[0, 1, 2]
C)
error, ‘;’ is not allowed
D)
error, **+ is not a valid operator

Correct Answer : Option (B) :   [0, 1, 2]

133 .
What will be the output of the following Python code snippet?
 
print([i.lower() for i in "HELLO"])
A)
‘hello’
B)
hello
C)
[‘hello’]
D)
[‘h’, ‘e’, ‘l’, ‘l’, ‘o’]

Correct Answer : Option (D) :   [‘h’, ‘e’, ‘l’, ‘l’, ‘o’]

134 .
What will be the output of the following Python code snippet?
 
print([[i+j for i in "abc"] for j in "def"])
A)
[[‘da’, ‘db’, ‘dc’], [‘ea’, ‘eb’, ‘ec’], [‘fa’, ‘fb’, ‘fc’]]
B)
[[‘ad’, ‘bd’, ‘cd’], [‘ae’, ‘be’, ‘ce’], [‘af’, ‘bf’, ‘cf’]]
C)
[‘da’, ‘ea’, ‘fa’, ‘db’, ‘eb’, ‘fb’, ‘dc’, ‘ec’, ‘fc’]
D)
[‘ad’, ‘ae’, ‘af’, ‘bd’, ‘be’, ‘bf’, ‘cd’, ‘ce’, ‘cf’]

Correct Answer : Option (B) :   [[‘ad’, ‘bd’, ‘cd’], [‘ae’, ‘be’, ‘ce’], [‘af’, ‘bf’, ‘cf’]]

135 .
Which of the following is the same as list(map(lambda x: x**-1, [1, 2, 3]))?
A)
[x**-1 for x in [(1, 2, 3)]]
B)
[1/x for x in [(1, 2, 3)]]
C)
[1/x for x in (1, 2, 3)]
D)
None of the above

Correct Answer : Option (C) :   [1/x for x in (1, 2, 3)]

136 .
Read the information given below carefully and write a list comprehension such that the output is: [‘e’, ‘o’]
 
w="hello"
v=('a', 'e', 'i', 'o', 'u')
A)
[x for w in v if x in v]
B)
[x for x in w if x in v]
C)
[x for x in v if w in v]
D)
[x for v in w for x in w]

Correct Answer : Option (B) :   [x for x in w if x in v]

137 .
What will be the output of the following Python code?
 
t=32.00
[round((x-32)*5/9) for x in t]
A)
0
B)
[0]
C)
[0.00]
D)
Error

Correct Answer : Option (D) :   Error

138 .
Write a list comprehension for producing a list of numbers between 1 and 1000 that are divisible by 3.
A)
[x%3 for x in range(1, 1000)]
B)
[x in range(1, 1000) if x%3==0]
C)
[x for x in range(1000) if x%3==0]
D)
[x%3=0 for x in range(1, 1000)]

Correct Answer : Option (C) :   [x for x in range(1000) if x%3==0]

139 .
Write a list comprehension equivalent for the Python code shown below.
 
for i in range(1, 101):
	if int(i*0.5)==i*0.5:
		print(i)
A)
[i for i in range(1, 100) if int(i*0.5)==(i*0.5)]
B)
[i for i in range(1, 101) if int(i*0.5)==(i*0.5)]
C)
[i for i in range(1, 101) if int(i*0.5)=(i*0.5)]
D)
[i for i in range(1, 100) if int(i*0.5)=(i*0.5)]

Correct Answer : Option (B) :   [i for i in range(1, 101) if int(i*0.5)==(i*0.5)]

140 .
Write a list comprehension to produce the list: [1, 2, 4, 8, 16……212].
A)
[(2**x) for x in range(0, 13)]
B)
[(x**2) for x in range(1, 13)]
C)
[(2**x) for x in range(1, 13)]
D)
[(x**2) for x in range(0, 13)]

Correct Answer : Option (A) :   [(2**x) for x in range(0, 13)]

141 .
What will be the output of the following Python code?
 
l=["good", "oh!", "excellent!", "#450"]
[n for n in l if n.isalpha() or n.isdigit()]
A)
[‘good’]
B)
[‘good’, ‘#450’]
C)
[‘oh!’, ‘excellent!’, ‘#450’]
D)
[‘good’, ‘oh’, ‘excellent’, ‘450’ ]

Correct Answer : Option (A) :   [‘good’]

142 .
What will be the output of the following Python code?
 
A = [[1, 2, 3],
          [4, 5, 6],
          [7, 8, 9]]
A[1]
A)
[1, 2, 3]
B)
[1, 4, 7]
C)
[3, 6, 9]
D)
[4, 5, 6]

Correct Answer : Option (D) :   [4, 5, 6]

143 .
What will be the output of the following Python code?
 
A = [[1, 2, 3],
      [4, 5, 6],
      [7, 8, 9]]
[A[row][1] for row in (0, 1, 2)]
A)
[1, 4, 7]
B)
[2, 5, 8]
C)
[4, 5, 6]
D)
[7, 8, 9]

Correct Answer : Option (B) :   [2, 5, 8]

144 .
What will be the output of the following Python code?
 
l=[[1, 2, 3], [4, 5, 6]]
for i in range(len(l)):
	for j in range(len(l[i])):
		l[i][j]+=10
l
A)
Error
B)
No output
C)
[[1, 2, 3], [4, 5, 6]]
D)
[[11, 12, 13], [14, 15, 16]]

Correct Answer : Option (D) :   [[11, 12, 13], [14, 15, 16]]

145 .
What will be the output of the following Python code?
 
A = [[1, 2, 3],
     [4, 5, 6],
     [7, 8, 9]]
 
[[col + 10 for col in row] for row in A]
A)
Error
B)
[11, 12, 13, 14, 15, 16, 17, 18, 19]
C)
[[11, 12, 13], [14, 15, 16], [17, 18, 19]]
D)
[11, 12, 13], [14, 15, 16], [17, 18, 19]

Correct Answer : Option (C) :   [[11, 12, 13], [14, 15, 16], [17, 18, 19]]

146 .
What will be the output of the following Python code?
 
A = [[1, 2, 3],
     [4, 5, 6],
     [7, 8, 9]]
B = [[3, 3, 3],
     [4, 4, 4],
     [5, 5, 5]]
[[col1 * col2 for (col1, col2) in zip(row1, row2)] for (row1, row2) in zip(A, B)]
A)
Error
B)
No output
C)
[[3, 6, 9], [16, 20, 24], [35, 40, 45]]
D)
[0, 30, 60, 120, 160, 200, 300, 350, 400]

Correct Answer : Option (C) :   [[3, 6, 9], [16, 20, 24], [35, 40, 45]]

147 .
Suppose t = (1, 2, 4, 3), which of the following is incorrect?
A)
print(t[3])
B)
t[3] = 45
C)
print(len(t))
D)
print(max(t))

Correct Answer : Option (B) :   t[3] = 45

148 .
What will be the output of the following Python code?
 
>>>t=(1,2,4,3)
>>>t[1:3]
A)
(1, 2)
B)
(1, 2, 4)
C)
(2, 4)
D)
(2, 4, 3)

Correct Answer : Option (C) :   (2, 4)

149 .
What will be the output of the following Python code?
 
>>>t = (1, 2, 4, 3, 8, 9)
>>>[t[i] for i in range(0, len(t), 2)]
A)
[1, 2, 4, 3, 8, 9]
B)
[2, 3, 9]
C)
(1, 4, 8)
D)
[1, 4, 8]

Correct Answer : Option (D) :   [1, 4, 8]

150 .
What will be the output of the following Python code?
 
numberGames = {}
numberGames[(1,2,4)] = 8
numberGames[(4,2,1)] = 10
numberGames[(1,2)] = 12
sum = 0
for k in numberGames:
    sum += numberGames[k]
print len(numberGames) + sum
A)
33
B)
30
C)
24
D)
12

Correct Answer : Option (A) :   33

151 .
 Is the following Python code valid?
 
>>> a,b=1,2,3
A)
Yes, this is an example of tuple unpacking. a=1 and b=2
B)
Yes, this is an example of tuple unpacking. a=(1,2) and b=3
C)
Yes, this is an example of tuple unpacking. a=1 and b=(2,3)
D)
No, too many values to unpack

Correct Answer : Option (D) :   No, too many values to unpack

152 .
What will be the output of the following Python code?
 
>>> a,b=6,7
>>> a,b=b,a
>>> a,b
A)
(6,7)
B)
(7,6)
C)
Invalid syntax
D)
Nothing is printed

Correct Answer : Option (B) :   (7,6)

153 .
Is the following Python code valid?
 
>>> a=2,3,4,5
>>> a
A)
Yes, 2 is printed
B)
Yes, [2,3,4,5] is printed
C)
Yes, (2,3,4,5) is printed
D)
No, too many values to unpack

Correct Answer : Option (D) :   Yes, (2,3,4,5) is printed

154 .
Is the following Python code valid?
 
>>> a=(1,2,3)
>>> b=a.update(4,)
A)
Yes, a=(1,2,3) and b=(1,2,3,4)
B)
Yes, a=(1,2,3,4) and b=(1,2,3,4)
C)
No because wrong syntax for update() method
D)
No because tuples are immutable

Correct Answer : Option (D) :   No because tuples are immutable

155 .
Which of the following is not the correct syntax for creating a set?
A)
set([[1,2],[3,4]])
B)
set([1,2,2,3,4])
C)
set((1,2,3,4))
D)
{1,2,3,4}

Correct Answer : Option (A) :   set([[1,2],[3,4]])

156 .
What will be the output of the following Python code?
 
a = [5,5,6,7,7,7]
b = set(a)
def test(lst):
    if lst in b:
        return 1
    else:
        return 0
for i in  filter(test, a):
    print(i,end=" ")
A)
5 5 6
B)
5 6 7
C)
5 5 6 7 7 7
D)
5 6 7 7 7

Correct Answer : Option (C) :   5 5 6 7 7 7

157 .
What will be the output of the following Python code?
 
>>> a={5,4}
>>> b={1,2,4,5}
>>> a<b
A)
True
B)
False
C)
{1,2}
D)
Invalid operation

Correct Answer : Option (A) :   True

158 .
What will be the output of the following Python code?
 
>>> a={4,5,6}
>>> b={2,8,6}
>>> a-b
A)
{6}
B)
{4,5}
C)
Error as unsupported operand type for set data type
D)
Error as the duplicate item 6 is present in both sets

Correct Answer : Option (B) :   {4,5}

159 .
What will be the output of the following Python code?
 
>>> a={3,4,5}
>>> b={5,6,7}
>>> a|b
A)
{5}
B)
{3,4,6,7}
C)
{3, 4, 5, 6, 7}
D)
Invalid operation

Correct Answer : Option (C) :   {3, 4, 5, 6, 7}

160 .
What will be the output of the following Python code?
 
s=set()
type(s)
A)
<class ‘set’>
B)
<’set’>
C)
class set
D)
set

Correct Answer : Option (A) :   <class ‘set’>

161 .
Which of the following lines of code will result in an error?
A)
s={abs}
B)
s={san}
C)
s={4, ‘abc’, (1,2)}
D)
s={2, 2.2, 3, ‘xyz’}

Correct Answer : Option (B) :   s={san}

162 .
Write a list comprehension for number and its cube for:
 
l=[1, 2, 3, 4, 5, 6, 7, 8, 9]
A)
[x**3 for x in l]
B)
[x^3 for x in l]
C)
[x**3 in l]
D)
[x^3 in l]

Correct Answer : Option (A) :   [x**3 for x in l]

163 .
What will be the output of the following Python code?
 
s1={3, 4}
s2={1, 2}
s3=set()
i=0
j=0
for i in s1:
    for j in s2:
        s3.add((i,j))
        i+=1
        j+=1
print(s3)
A)
Error
B)
{(3, 4), (1, 2)}
C)
{(3, 1), (4, 2)}
D)
{(4, 2), (3, 1), (4, 1), (5, 2)}

Correct Answer : Option (D) :   {(4, 2), (3, 1), (4, 1), (5, 2)}

164 .
The ____ function removes the first element of a set and the last element of a list.
A)
pop
B)
remove
C)
dispose
D)
discard

Correct Answer : Option (A) :   pop

165 .
If we have two sets, s1 and s2, and we want to check if all the elements of s1 are present in s2 or not, we can use the function:
A)
s1.isset(s2)
B)
s2.issubset(s1)
C)
s2.issuperset(s1)
D)
s1.issuperset(s2)

Correct Answer : Option (C) :   s2.issuperset(s1)

166 .
What will be the output of the following Python code snippet?
 
>>> a={1:"A",2:"B",3:"C"}
>>> del a
A)
del deletes the entire dictionary
B)
del deletes the values in the dictionary
C)
del deletes the keys in the dictionary
D)
method del doesn’t exist for the dictionary

Correct Answer : Option (A) :   del deletes the entire dictionary

167 .
What will be the output of the following Python code snippet?
 
total={}
def insert(items):
    if items in total:
        total[items] += 1
    else:
        total[items] = 1
insert('Apple')
insert('Ball')
insert('Apple')
print (len(total))
A)
0
B)
1
C)
2
D)
3

Correct Answer : Option (C) :   2

168 .
What will be the output of the following Python code snippet?
 
numbers = {}
letters = {}
comb = {}
numbers[1] = 56
numbers[3] = 7
letters[4] = 'B'
comb['Numbers'] = numbers
comb['Letters'] = letters
print(comb)
A)
{‘Numbers’: {1: 56}, ‘Letters’: {4: ‘B’}}
B)
{‘Numbers’: {1: 56, 3: 7}, ‘Letters’: {4: ‘B’}}
C)
‘Numbers’: {1: 56, 3: 7}
D)
Error, dictionary in a dictionary can’t exist

Correct Answer : Option (B) :   {‘Numbers’: {1: 56, 3: 7}, ‘Letters’: {4: ‘B’}}

169 .
What will be the output of the following Python code snippet?
 
test = {1:'A', 2:'B', 3:'C'}
del test[1]
test[1] = 'D'
del test[2]
print(len(test))
A)
2
B)
1
C)
0
D)
Error as the key-value pair of 1:’A’ is already deleted

Correct Answer : Option (A) :   2

170 .
What will be the output of the following Python code snippet?
 
a={}
a['a']=1
a['b']=[2,3,4]
print(a)
A)
{‘b’: [2], ‘a’: 1}
B)
{‘b’: [2], ‘a’: [3]}
C)
{‘b’: [2, 3, 4], ‘a’: 1}
D)
Exception is thrown

Correct Answer : Option (C) :   {‘b’: [2, 3, 4], ‘a’: 1}

171 .
What will be the output of the following Python code snippet?
 
>>>import collections
>>> b=collections.Counter([2,2,3,4,4,4])
>>> b.most_common(1)
A)
{3:1}
B)
{4:3}
C)
[(4, 3)]
D)
Counter({4: 3, 2: 2, 3: 1})

Correct Answer : Option (C) :   [(4, 3)]

172 .
What will be the output of the following Python code snippet?
 
>>> import collections
>>> a=collections.Counter([2,2,3,3,3,4])
>>> b=collections.Counter([2,2,3,4,4])
>>> a|b
A)
Counter({3: 3, 2: 2, 4: 2})
B)
Counter({2: 2, 3: 1, 4: 1})
C)
Counter({3: 2})
D)
Counter({4: 1})

Correct Answer : Option (A) :   Counter({3: 3, 2: 2, 4: 2})

173 .
The function pow(x,y,z) is evaluated as:
A)
(x**y)**z
B)
(x**y) / z
C)
(x**y) % z
D)
(x**y)*z

Correct Answer : Option (C) :   (x**y) % z

174 .
What will be the output of the following Python function?
 
any([2>8, 4>2, 1>2])
A)
True
B)
False
C)
4>2
D)
Error

Correct Answer : Option (A) :   True

175 .
What will be the output of the following Python function?
 
min(max(False,-3,-4), 2,7)
A)
2
B)
-3
C)
-4
D)
False

Correct Answer : Option (D) :   False

176 .
Suppose there is a list such that: l=[2,3,4]. If we want to print this list in reverse order, which of the following methods should be used?
A)
list(reversed(l))
B)
list(reverse[(l)])
C)
reversed(l)
D)
reverse(l)

Correct Answer : Option (A) :   list(reversed(l))

177 .
Which of the following functions does not throw an error?
A)
ord()
B)
ord(‘ ‘)
C)
ord(”)
D)
ord(“”)

Correct Answer : Option (B) :   ord(‘ ‘)

178 .
What will be the output of the following Python code?
 
def printMax(a, b):
    if a > b:
        print(a, 'is maximum')
    elif a == b:
        print(a, 'is equal to', b)
    else:
        print(b, 'is maximum')
printMax(3, 4)
A)
3
B)
4
C)
4 is maximum
D)
None of the above

Correct Answer : Option (C) :   4 is maximum

179 .
What will be the output of the following Python code?
 
def maximum(x, y):
    if x > y:
        return x
    elif x == y:
        return 'The numbers are equal'
    else:
        return y
 
print(maximum(2, 3))
A)
2
B)
3
C)
The numbers are equal
D)
None of the above

Correct Answer : Option (B) :   3

180 .
Which are the advantages of functions in python?
A)
Reducing duplication of code
B)
Improving clarity of the code
C)
Decomposing complex problems into simpler pieces
D)
All of the mentioned

Correct Answer : Option (D) :   All of the mentioned

181 .
What will be the output of the following Python code?
 
def cube(x):
    return x * x * x      
x = cube(3)    
print x
A)
3
B)
9
C)
27
D)
30

Correct Answer : Option (C) :   27

182 .
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

Correct Answer : Option (C) :   A local variable

183 .
What will be the output of the following Python code?
 
i=0
def change(i):
   i=i+1
   return i
change(1)
print(i)
A)
0
B)
1
C)
Nothing is displayed
D)
An exception is thrown

Correct Answer : Option (A) :   0

184 .
What will be the output of the following Python code?
 
def a(b):
    b = b + [5]
 
c = [1, 2, 3, 4]
a(c)
print(len(c))
A)
4
B)
5
C)
An exception is thrown
D)
None of the above

Correct Answer : Option (B) :   5

185 .
What will be the output of the following Python code?
 
def display(b, n):
    while n > 0:
        print(b,end="")
        n=n-1
display('z',3)
A)
zzz
B)
zz
C)
Infinite loop
D)
None of the above

Correct Answer : Option (A) :   zzz

186 .
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 above

Correct Answer : Option (B) :   number of arguments + 1

187 .
What will be the output of the following Python code?
 
def foo(k):
    k[0] = 1
q = [0]
foo(q)
print(q)
A)
[1, 0]
B)
[0, 1]
C)
[0]
D)
[1]

Correct Answer : Option (D) :   [1]

188 .
What will be the output of the following Python 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 above

Correct Answer : Option (A) :   3 1

189 .
What will be the output of the following Python code?
 
def foo(x):
    x = ['def', 'abc']
    return id(x)
q = ['abc', 'def']
print(id(q) == foo(q))
A)
True
B)
False
C)
Error
D)
None

Correct Answer : Option (B) :   False

190 .
What will be the output of the following Python code?
 
def foo(i, x=[]):
    x.append(i)
    return x
for i in range(3):
    print(foo(i))
A)
[0] [1] [2]
B)
[1] [2] [3]
C)
[0] [0, 1] [0, 1, 2]
D)
[1] [1, 2] [1, 2, 3]

Correct Answer : Option (C) :   [0] [0, 1] [0, 1, 2]

191 .
What will be the output of the following Python code?
 
def f1():
    x=15
    print(x)
x=12
f1()
A)
Error
B)
12
C)
15
D)
1512

Correct Answer : Option (C) :   15

192 .
What will be the output of the following Python code?
 
def san(x):
    print(x+1)
x=-2
x=4
san(12)
A)
2
B)
5
C)
10
D)
13

Correct Answer : Option (D) :   13

193 .
What will be the output of the following Python code?
 
x=12
def f1(a,b=x):
    print(a,b)
x=15
f1(4)
A)
12 4
B)
4 12
C)
4 15
D)
Error

Correct Answer : Option (B) :   4 12

194 .
Fill in the line of the following Python code for calculating the factorial of a number.
 
def fact(num):
    if num == 0: 
        return 1
    else:
        return ________
A)
num*fact(num-1)
B)
(num-1)*(num-2)
C)
fact(num)*fact(num-1)
D)
num*(num-1)

Correct Answer : Option (A) :   num*fact(num-1)

195 .
What will be the output of the following Python code?
 
def test(i,j):
    if(i==0):
        return j
    else:
        return test(i-1,i+j)
print(test(4,7))
A)
Infinite loop
B)
7
C)
13
D)
17

Correct Answer : Option (D) :   17

196 .
What will be the output of the following Python code?
 
l=[]
def convert(b):
    if(b==0):
        return l
    dig=b%2
    l.append(dig)
    convert(b//2)
convert(6)
l.reverse()
for i in l:
    print(i,end="")
A)
011
B)
110
C)
Infinite loop
D)
None of the above

Correct Answer : Option (B) :   110

197 .
What will be the output of the following Python code?
 
def fun(n):
    if (n > 100):
        return n - 5
    return fun(fun(n+11));
 
print(fun(45))
A)
50
B)
74
C)
100
D)
Infinite loop

Correct Answer : Option (C) :   100

198 .
What will be the output of the following Python code?
 
def check(n):
    if n < 2:
        return n % 2 == 0
    return check(n - 2)
print(check(11))
A)
True
B)
False
C)
An exception is thrown
D)
None of the above

Correct Answer : Option (B) :   False

199 .
What will be the output of the following Python code?
 
def a(n):
    if n == 0:
        return 0
    elif n == 1:
        return 1
    else:
        return a(n-1)+a(n-2)
for i in range(0,4):
    print(a(i),end=" ")
A)
An exception is thrown
B)
0 1 2 3
C)
0 1 1 2 3
D)
0 1 1 2

Correct Answer : Option (D) :   0 1 1 2

200 .
What will be the output of the following Python code?
 
a = [1, 2, 3, 4, 5]
b = lambda x: (b (x[1:]) + x[:1] if x else []) 
print(b (a))
A)
1 2 3 4 5
B)
[5,4,3,2,1]
C)
[ ]
D)
None of the above

Correct Answer : Option (C) :   [ ]

201 .
What will be the output of the following Python code?
 
odd=lambda x: bool(x%2)
numbers=[n for n in range(10)]
print(numbers)
n=list()
for i in numbers:
    if odd(i):
        continue
    else:
        break
A)
[1, 3, 5, 7, 9]
B)
[0, 2, 4, 6, 8, 10]
C)
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
D)
None of the above

Correct Answer : Option (C) :   [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

202 .
What will be the output of the following Python code?
 
import functools
l=[1,2,3,4]
print(functools.reduce(lambda x,y:x*y,l))
A)
10
B)
24
C)
Error
D)
None of the above

Correct Answer : Option (B) :   24

203 .
What will be the output of the following Python code?
 
l=[1, -2, -3, 4, 5]
def f1(x):
    return x<-1
m1=map(f1, l)
print(list(m1))
A)
[False, True, True, False, False]
B)
[True, True, True, True, True]
C)
[True, False, False, True, True]
D)
[False, False, False, False, False]

Correct Answer : Option (A) :   [False, True, True, False, False]

204 .
What will be the output of the following Python code?
 
import functools
l=[1, 2, 3, 4, 5]
m=functools.reduce(lambda x, y:x if x>y else y, l)
print(m)
A)
Error
B)
Address of m
C)
1
D)
5

Correct Answer : Option (D) :   5

205 .
What will be the output of the following Python code?
 
m=reduce(lambda x: x-3 in range(4, 10))
print(list(m))
A)
[1, 2, 3, 4, 5, 6]
B)
[1, 2, 3, 4, 5, 6, 7]
C)
No output
D)
Error

Correct Answer : Option (C) :   No output

206 .
What will be the output of the following Python code?
 
elements = [0, 1, 2]
def incr(x):
    return x+1
print(list(map(incr, elements)))
A)
[1, 2, 3]
B)
[0, 1, 2]
C)
Error
D)
None of the above

Correct Answer : Option (A) :   [1, 2, 3]

207 .
What will be the output of the following Python code?
 
def to_upper(k):
    return k.upper()
x = ['ab', 'cd']
print(list(map(upper, x)))
A)
[‘AB’, ‘CD’]
B)
[‘ab’, ‘cd’]
C)
Error
D)
None of the above

Correct Answer : Option (C) :   Error

208 .
What will be the output of the following Python code?
 
x = ['ab', 'cd']
print(map(len, x))
A)
[‘ab’, ‘cd’]
B)
[‘2’, ‘2’]
C)
[2, 2]
D)
None of the above

Correct Answer : Option (D) :   None of the above

209 .
What will be the output of the following Python code?
 
x = ['ab', 'cd']
print(len(list(map(list, x))))
A)
0
B)
2
C)
4
D)
None of the above

Correct Answer : Option (B) :   2

210 .
What will be the output of the following Python code?
 
x = [[0], [1]]
print((' '.join(list(map(str, x))),))
A)
(‘[0] [1]’,)
B)
[0] [1]
C)
(’01’)
D)
01

Correct Answer : Option (A) :   (‘[0] [1]’,)

211 .
What will be the output of the following Python code?
 
x = [34, 56]
print((''.join(list(map(str, x)))),)
A)
3456
B)
(3456)
C)
(‘3456’)
D)
(‘3456’,)

Correct Answer : Option (A) :   3456

212 .
What will be the output of the following Python code?
 
x = 'abcd'
print(list(map(list, x)))
A)
[‘abcd’]
B)
[‘a’, ‘b’, ‘c’, ‘d’]
C)
[[‘a’], [‘b’], [‘c’], [‘d’]]
D)
None of the above

Correct Answer : Option (C) :   [[‘a’], [‘b’], [‘c’], [‘d’]]

213 .
Is Python code compiled or interpreted?
A)
Python code is both compiled and interpreted
B)
Python code is neither compiled nor interpreted
C)
Python code is only interpreted
D)
Python code is only compiled

Correct Answer : Option (A) :   Python code is both compiled and interpreted

214 .
Which of these is false about a package?
A)
A package can have subfolders and modules
B)
Each import package need not introduce a namespace
C)
import folder.subfolder.mod1 imports packages
D)
from folder.subfolder.mod1 import objects imports packages

Correct Answer : Option (B) :   Each import package need not introduce a namespace

215 .
Which of the following is not an advantage of using modules?
A)
Provides a means of dividing up tasks
B)
Provides a means of reuse of program code
C)
Provides a means of reducing the size of the program
D)
Provides a means of testing individual parts of the program

Correct Answer : Option (C) :   Provides a means of reducing the size of the program

216 .
______ is a string literal denoted by triple quotes for providing the specifications of certain program elements.
A)
Interface
B)
Client
C)
Modularity
D)
Docstring

Correct Answer : Option (D) :   Docstring

217 .
Which of the following is true about top-down design process?
A)
Only the design of the program is addressed
B)
Only the details of the program are addressed
C)
The overall design of the program is addressed before the details
D)
The details of a program design are addressed before the overall design

Correct Answer : Option (C) :   The overall design of the program is addressed before the details

218 .
What will be the output of the following Python code?
 
from math import factorial
print(math.factorial(5))
A)
120
B)
Nothing is printed
C)
Error, method factorial doesn’t exist in math module
D)
Error, the statement should be: print(factorial(5))

Correct Answer : Option (D) :   Error, the statement should be: print(factorial(5))

219 .
What will be the output of print(math.copysign(3, -1))?
A)
-3.0
B)
-3
C)
1.0
D)
1

Correct Answer : Option (A) :   -3.0

220 .
What is math.factorial(4.0)?
A)
1
B)
24
C)
Error
D)
None of the above

Correct Answer : Option (B) :   24

221 .
What will be the output of the following Python code?
 
import datetime
d=datetime.date(2016,7,24)
print(d)
A)
Error
B)
24-7-2017
C)
2017-7-24
D)
2017-07-24

Correct Answer : Option (D) :   2017-07-24

222 .
What will be the output of the following Python code if the system date is 18th August, 2016?
 
tday=datetime.date.today()
print(tday.month())
A)
8
B)
08
C)
Aug
D)
August

Correct Answer : Option (A) :   8

223 .
Which of the following will throw an error if used after the following Python code?
 
tday=datetime.date.today()
bday=datetime.date(2017,9,18)
t_day=bday-tday
A)
print(t_day.max)
B)
print(t_day.months)
C)
print(t_day.seconds)
D)
print(t_day.resolution)

Correct Answer : Option (B) :   print(t_day.months)

224 .
To include the use of functions which are present in the random library, we must use the option:
A)
import random
B)
import.random
C)
random.random
D)
random.h

Correct Answer : Option (A) :   import random

225 .
What will be the output of the following Python code?
 
import random
random.choice(2,3,4)
A)
3 only
B)
Either 2, 3 or 4
C)
An integer other than 2, 3 and 4
D)
Error

Correct Answer : Option (D) :   Error

226 .
What will be the output of the following Python function (random module has already been imported)?
 
random.choice('sun')
A)
u
B)
sun
C)
either s, u or n
D)
Error

Correct Answer : Option (C) :   either s, u or n

227 .
What will be the output of the following Python code?
 
random.seed(3)
random.randint(1,5)
2
random.seed(3)
random.randint(1,5)
A)
2
B)
3
C)
Any integer between 1 and 5, including 1 and 5
D)
Any integer between 1 and 5, excluding 1 and 5

Correct Answer : Option (A) :   2

228 .
What will be the output of the following Python code?
 
random.randrange(1,100,10)
A)
32
B)
67
C)
91
D)
180

Correct Answer : Option (C) :   91

229 .
Which of the following functions can help us to find the version of python that we are currently working on?
A)
sys.version
B)
sys.version()
C)
sys.version(0)
D)
sys.version(1)

Correct Answer : Option (A) :   sys.version

230 .
What will be the output of the following Python code, if the code is run on Windows operating system?
 
import sys
if sys.platform[:2]== 'wi':
	print("Hello")
A)
Error
B)
Hello
C)
Junk value
D)
No output

Correct Answer : Option (B) :   Hello

231 .
What will be the output of the following Python code?
 
import sys
eval(sys.stdin.readline())
"India"
A)
India
B)
India5
C)
‘India\n’
D)
‘India’

Correct Answer : Option (D) :   ‘India’

232 .
What will be the output of the following Python code?
 
import sys
sys.stderr.write(“hello”)
A)
hello
B)
‘hello’
C)
hello5
D)
‘hello\n’

Correct Answer : Option (C) :   hello5

233 .
To obtain a list of all the functions defined under sys module, which of the following functions can be used?
A)
print(sys)
B)
print(dir.sys)
C)
print(dir[sys])
D)
print(dir(sys))

Correct Answer : Option (D) :   print(dir(sys))

234 .
What does print(os.geteuid()) print?
A)
the group id of the current process
B)
the user id of the current process
C)
both the group id and the user of the current process
D)
None of the above

Correct Answer : Option (B) :   the user id of the current process

235 .
Which of the following can be used to create a directory?
A)
os.mkdir()
B)
os.creat_dir()
C)
os.make_dir()
D)
os.create_dir()

Correct Answer : Option (A) :   os.mkdir()

236 .
What will be the output shape of the following Python code?
 
import turtle
t=turtle.Pen()
for i in range(0,4):
	t.forward(100)
	t.left(120)
A)
kite
B)
square
C)
triangle
D)
rectangle

Correct Answer : Option (C) :   triangle

237 .
Fill in the blank such that the following Python code results in the formation of an inverted, equilateral triangle.
 
import turtle
t=turtle.Pen()
for i in range(0,3):
	t.forward(150)
	t.right(_____)
A)
-60
B)
120
C)
-120
D)
60

Correct Answer : Option (B) :   120

238 .
What will be the output of the following Python code?
 
import turtle
t=turtle.Pen()
t.goto(300,9)
t.position()
A)
300.00, 9.00
B)
9.00, 300.00
C)
9, 300
D)
300, 9

Correct Answer : Option (A) :   300.00, 9.00

239 .
What will be the output of the following Python functions?
 
import turtle
t=turtle.Pen()
for i in range(0,3):
	t.forward(100)
	t.left(120)
 
t.back(100)
for i in range(0,3):
	t.forward(100)
	t.left(120)
A)
Error
B)
Two triangles, joined at one vertex
C)
Two triangles, joined by a straight line
D)
Two separate triangles, not connected by a line

Correct Answer : Option (B) :   Two triangles, joined at one vertex

240 .
The function used to alter the thickness of the pen to ‘x’ units:
A)
turtle.span(x)
B)
turtle.width(x)
C)
turtle.girth(x)
D)
turtle.thickness(x)

Correct Answer : Option (B) :   turtle.width(x)

241 .
The output of the following Python code is similar to the alphabet _______________
 
import turtle
t=turtle.Pen()
t1=turtle.Pen()
t2=turtle.Pen()
t.forward(100)
t1.forward(100)
t2.forward(100)
t1.left(90)
t1.forward(75)
t2.right(90)
t2.forward(75)
A)
M
B)
N
C)
T
D)
X

Correct Answer : Option (C) :   T

242 .
What will be the output shape of the following Python code?
 
import turtle
t=turtle.Pen()
for i in range(0,6):
	t.forward(100)
	t.left(60)
A)
Hexagon
B)
Octagon
C)
Pentagon
D)
Heptagon

Correct Answer : Option (A) :   Hexagon

243 .
What will be the output of the following Python code?
 
import turtle
t=turtle.Pen()
t.resizemode(“freetimelearn”)
t.resizemode()
A)
user
B)
auto
C)
nonresize
D)
Error

Correct Answer : Option (C) :   nonresize

244 .
To sterilize an object hierarchy, the _____________ function must be called. To desterilize a data stream, the ______________ function must be called.
A)
dumps(), undumps()
B)
loads(), unloads()
C)
loads(), dumps()
D)
dumps(), loads()

Correct Answer : Option (D) :   dumps(), loads()

245 .
Which of the following Python codes will result in an error?
 
object = ‘a’
A)
>>> pickle.dumps(object)
B)
>>> pickle.dumps(object, 3)
C)
>>> pickle.dumps(object, 3, True)
D)
>>> pickle.dumps(‘a’, 2)

Correct Answer : Option (C) :   >>> pickle.dumps(object, 3, True)

246 .
Which of the following functions can be used to find the protocol version of the pickle module currently being used?
A)
pickle.DEFAULT_PROTOCOL
B)
pickle.CURRENT_PROTOCOL
C)
pickle.CURRENT
D)
pickle.DEFAULT

Correct Answer : Option (A) :   pickle.DEFAULT_PROTOCOL

247 .
Which of the following functions can accept more than one positional argument?
A)
pickle.load
B)
pickle.dumps
C)
pickle.loads
D)
pickle.dump

Correct Answer : Option (B) :   pickle.dumps

248 .
The pickle module defines ______ exceptions and exports _______ classes.
A)
2, 3
B)
3, 4
C)
3, 2
D)
4, 3

Correct Answer : Option (C) :   3, 2

249 .
If __getstate__() returns _______________ the __setstate__() module will not be called on pickling.
A)
True value
B)
False value
C)
ValueError
D)
OverflowError

Correct Answer : Option (B) :   False value

250 .
The copy module uses the ________ protocol for shallow and deep copy.
A)
pickle
B)
shelve
C)
marshal
D)
copyreg

Correct Answer : Option (A) :   pickle

251 .
Which module in Python supports regular expressions?
A)
re
B)
regex
C)
pyregex
D)
None of the above

Correct Answer : Option (A) :   re

252 .
Which of the following creates a pattern object?
A)
re.create(str)
B)
re.regex(str)
C)
re.compile(str)
D)
re.assemble(str)

Correct Answer : Option (C) :   re.compile(str)

253 .
What does the function re.match do?
A)
matches a pattern at the start of the string
B)
matches a pattern at any position in the string
C)
such a function does not exist
D)
None of the above

Correct Answer : Option (A) :   matches a pattern at the start of the string

254 .
What will be the output of the following Python code?
 
sentence = 'we are humans'
matched = re.match(r'(.*) (.*?) (.*)', sentence)
print(matched.groups())
A)
(‘we’, ‘humans’)
B)
(‘we’, ‘are’, ‘humans’)
C)
(we, are, humans)
D)
‘we are humans’

Correct Answer : Option (B) :   (‘we’, ‘are’, ‘humans’)

255 .
What will be the output of the following Python code?
 
sentence = 'we are humans'
matched = re.match(r'(.*) (.*?) (.*)', sentence)
print(matched.group(2))
A)
‘we are humans’
B)
‘are’
C)
‘we’
D)
‘humans’

Correct Answer : Option (D) :   ‘humans’

256 .
What will be the output of the following Python code?
 
sentence = 'horses are fast'
regex = re.compile('(?P<animal>\w+) (?P<verb>\w+) (?P<adjective>\w+)')
matched = re.search(regex, sentence)
print(matched.groups())
A)
{‘animal’: ‘horses’, ‘verb’: ‘are’, ‘adjective’: ‘fast’}
B)
(‘horses’, ‘are’, ‘fast’)
C)
‘horses are fast’
D)
‘are’

Correct Answer : Option (B) :   (‘horses’, ‘are’, ‘fast’)

257 .
The expression a{5} will match _____________ characters with the previous regular expression.
A)
exactly 5
B)
5 or more
C)
5 or less
D)
exactly 4

Correct Answer : Option (B) :   exactly 5

258 .
What will be the output of the following Python code?
 
re.split('\W+', 'Hello, hello, hello.')
A)
[‘Hello, ‘hello’, ‘hello’]
B)
[‘Hello’, ‘hello’, ‘hello.’]
C)
[‘Hello’, ‘hello’, ‘hello’, ‘.’]
D)
[‘Hello’, ‘hello’, ‘hello’, ”]

Correct Answer : Option (D) :   [‘Hello’, ‘hello’, ‘hello’, ”]

259 .
Which of the following functions results in case insensitive matching?
A)
re.A
B)
re.U
C)
re.I
D)
re.X

Correct Answer : Option (C) :   re.I

260 .
Which of the following functions creates a Python object?
A)
re.compile(str)
B)
re.assemble(str)
C)
re.regex(str)
D)
re.create(str)

Correct Answer : Option (A) :   re.compile(str)

261 .
What will be the output of the following Python code?
 
s = 'welcome home'
m = re.match(r'(.*)(.*?)', s)
print(m.group())
A)
[‘welcome’ // ‘home’ ]
B)
[‘welcome’, ‘home’]
C)
(‘welcome’, ‘home’)
D)
welcome home

Correct Answer : Option (D) :   welcome home

262 .
What will be the output of the following Python code?
 
re.match('sp(.*)am', 'spam')
A)
<_sre.SRE_Match object; span=(1, 4), match=’spam’>
B)
<_sre.SRE_Match object; span=(0, 4), match=’spam’>
C)
No output
D)
None of the above

Correct Answer : Option (B) :  

<_sre.SRE_Match object; span=(0, 4), match=’spam’>

263 .
Which of the codes shown below results in a match?
A)
re.match(‘George(?=Washington)’, ‘George’)
B)
re.match(‘George(?=Washington)’, ‘George Washington’)
C)
re.match(‘George(?=Washington)’, ‘GeorgeWashington’)
D)
re.match(‘George(?=Washington)’, ‘Georgewashington’)

Correct Answer : Option (C) :   re.match(‘George(?=Washington)’, ‘GeorgeWashington’)

264 .
Which of the following statements regarding the output of the function re.match is incorrect?
A)
‘p{4}, q’ does not match ‘pppq’
B)
‘pq*’ will match ‘pq’
C)
‘pq?’ matches ‘p’
D)
‘pq+’ matches ‘p’

Correct Answer : Option (D) :   ‘pq+’ matches ‘p’

265 .
What will be the output of the following Python code?
 
a = re.compile('0-9')
a.findall('3 trees')
A)
[ ]
B)
[‘3’]
C)
[‘trees’]
D)
Error

Correct Answer : Option (C) :   Error

266 .
Which of the following lines of code will not show a match?
A)
>>> re.match(‘ab*’, ‘a’)
B)
>>> re.match(‘ab*’, ‘ba’)
C)
>>> re.match(‘ab*’, ‘ab’)
D)
>>> re.match(‘ab*’, ‘abb’)

Correct Answer : Option (B) :   >>> re.match(‘ab*’, ‘ba’)

267 .
What will be the output of the following Python code?
 
re.sub('Y', 'X', 'AAAAAA', count=2)
A)
‘AAAAAA’
B)
‘YXAAAA’
C)
(‘AAAAAA’)
D)
(‘YXAAAA’)

Correct Answer : Option (A) :   ‘AAAAAA’

268 .
To open a file c:\scores.txt for reading, we use _____________
A)
infile = open(“c:\scores.txt”, “r”)
B)
infile = open(“c:\\scores.txt”, “r”)
C)
infile = open(file = “c:\scores.txt”, “r”)
D)
infile = open(file = “c:\\scores.txt”, “r”)

Correct Answer : Option (B) :   infile = open(“c:\\scores.txt”, “r”)

269 .
To open a file c:\scores.txt for writing, we use ____________
A)
outfile = open(file = “c:\\scores.txt”, “w”)
B)
outfile = open(file = “c:\scores.txt”, “w”)
C)
outfile = open(“c:\scores.txt”, “w”)
D)
outfile = open(“c:\\scores.txt”, “w”)

Correct Answer : Option (D) :   outfile = open(“c:\\scores.txt”, “w”)

270 .
What will be the output of the following Python code?
 
f = None
for i in range (5):
    with open("data.txt", "w") as f:
        if i > 2:
            break
print(f.closed)
A)
True
B)
False
C)
None
D)
Error

Correct Answer : Option (A) :   True

271 .
To read the remaining lines of the file from a file object infile, we use _______
A)
infile.read(2)
B)
infile.read()
C)
infile.readline()
D)
infile.readlines()

Correct Answer : Option (D) :   infile.readlines()

272 .
What will be the output of the following Python code? (If entered name is freetimelearn)
 
import sys
print 'Enter your name: ',
name = ''
while True:
   c = sys.stdin.read(1)
   if c == '\n':
      break
   name = name + c
 
print 'Your name is:', name
A)
freetimelearn
B)
freetimelearn, freetimelearn
C)
Fre
D)
None of the above

Correct Answer : Option (A) :   freetimelearn

273 .
Which of the following mode will refer to binary data?
A)
r
B)
w
C)
b
D)
+

Correct Answer : Option (C) :   b

274 .
What will be the output of the following Python code?
 
fo = open("foo.txt", "wb")
print "Name of the file: ", fo.name
fo.flush()
fo.close()
A)
Runtime Error
B)
Compilation Error
C)
No Output
D)
Flushes the file when closing them

Correct Answer : Option (D) :   Flushes the file when closing them

275 .
Correct syntax of file.writelines() is?
A)
fileObject.writelines(sequence)
B)
file.writelines(sequence)
C)
fileObject.writelines()
D)
None of the above

Correct Answer : Option (A) :   fileObject.writelines(sequence)

276 .
How do you get the name of a file from a file object (fp)?
A)
fp.file(name)
B)
fp.name
C)
fp.__name__()
D)
self.__name__(fp)

Correct Answer : Option (B) :   fp.name

277 .
How do you close a file object (fp)?
A)
close(fp)
B)
fclose(fp)
C)
fp.close()
D)
fp.__close__()

Correct Answer : Option (C) :   fp.close()

278 .
How do you change the file position to an offset value from the start?
A)
fp.seek(offset, 0)
B)
fp.seek(offset, 1)
C)
fp.seek(offset, 2)
D)
None of the above

Correct Answer : Option (A) :   fp.seek(offset, 0)

279 .
Which function is called when the following Python code is executed?
 
f = foo()
format(f)
A)
str()
B)
__str__()
C)
format()
D)
__format__()

Correct Answer : Option (B) :   __str__()

280 .
Let A and B be objects of class Foo. Which functions are called when print(A + B) is executed?
A)
__str__(), __sum__()
B)
__sum__(), __str__()
C)
__str__(), __add__()
D)
__add__(), __str__()

Correct Answer : Option (D) :   __add__(), __str__()

281 .
Which function overloads the // operator?
A)
__div__()
B)
__ceildiv__()
C)
__floordiv__()
D)
__truediv__()

Correct Answer : Option (C) :   __floordiv__()

282 .
_____ represents an entity in the real world with its identity and behaviour.
A)
A class
B)
An object
C)
A method
D)
An operator

Correct Answer : Option (B) :   An object

283 .
What is getattr() used for?
A)
To access the attribute of the object
B)
To check if an attribute exists or not
C)
To delete an attribute
D)
To set an attribute

Correct Answer : Option (A) :   To access the attribute of the object

284 .
What will be the output of the following Python code?
 
 class test:
     def __init__(self,a):
         self.a=a
 
     def display(self):
         print(self.a)
obj=test()
obj.display()
A)
Runs normally, doesn’t display anything
B)
Displays 0, which is the automatic default value
C)
Error as one argument is required while creating the object
D)
Error as display function requires additional argument

Correct Answer : Option (C) :   Error as one argument is required while creating the object

285 .
What is Instantiation in terms of OOP terminology?
A)
Deleting an instance of class
B)
Modifying an instance of class
C)
Copying an instance of class
D)
Creating an instance of class

Correct Answer : Option (D) :   Creating an instance of class

286 .
What will be the output of the following Python code?
 
class fruits:
    def __init__(self, price):
        self.price = price
obj=fruits(50)
 
obj.quantity=10
obj.bags=2
 
print(obj.quantity+len(obj.__dict__))
A)
12
B)
13
C)
52
D)
60

Correct Answer : Option (B) :   13

287 .
Which of the following statements is wrong about inheritance?
A)
Protected members of a class can be inherited
B)
The inheriting class is called a subclass
C)
Inheritance is one of the features of OOP
D)
Private members of a class can be inherited and accessed

Correct Answer : Option (D) :   Private members of a class can be inherited and accessed

288 .
What will be the output of the following Python code?
 
class A():
    def disp(self):
        print("A disp()")
class B(A):
    pass
obj = B()
obj.disp()
A)
A disp()
B)
Invalid syntax for inheritance
C)
Nothing is printed
D)
None of the above

Correct Answer : Option (A) :   A disp()

289 .
Suppose B is a subclass of A, to invoke the __init__ method in A from B, what is the line of code you should write?
A)
A.__init__(B)
B)
B.__init__(A)
C)
A.__init__(self)
D)
B.__init__(self)

Correct Answer : Option (C) :   A.__init__(self)

290 .
What type of inheritance is illustrated in the following Python code?
 
class A():
    pass
class B():
    pass
class C(A,B):
    pass
A)
Multi-level inheritance
B)
Multiple inheritance
C)
Single-level inheritance
D)
Hierarchical inheritance

Correct Answer : Option (B) :   Multiple inheritance

291 .
What is the biggest reason for the use of polymorphism?
A)
The program will have a more elegant design and will be easier to maintain and update
B)
It allows the programmer to think at a more abstract level
C)
There is less program code to write
D)
Program code takes up less space

Correct Answer : Option (A) :   The program will have a more elegant design and will be easier to maintain and update

292 .
What will be the output of the following Python code?
 
class A:
    def __str__(self):
        return '1'
class B(A):
    def __init__(self):
        super().__init__()
class C(B):
    def __init__(self):
        super().__init__()
def main():
    obj1 = B()
    obj2 = A()
    obj3 = C()
    print(obj1, obj2,obj3)
main()
A)
‘1’ ‘1’ ‘1’
B)
1 2 3
C)
1 1 1
D)
An exception is thrown

Correct Answer : Option (C) :   1 1 1

293 .
What will be the output of the following Python code?
 
class A:
    def __init__(self):
        self.multiply(15)
        print(self.i)
 
    def multiply(self, i):
        self.i = 4 * i;
class B(A):
    def __init__(self):
        super().__init__()
 
    def multiply(self, i):
        self.i = 2 * i;
obj = B()
A)
An exception is thrown
B)
60
C)
30
D)
15

Correct Answer : Option (C) :   30

294 .
Is the following Python code valid?
 
try:
    # Do something
except:
    # Do something
finally:
    # Do something
A)
no, there is no such thing as finally
B)
no, finally cannot be used with except
C)
no, finally must come before except
D)
None of the above

Correct Answer : Option (B) :   no, finally cannot be used with except

295 .
What will be the output of the following Python code?
 
def foo():
    try:
        return 1
    finally:
        return 2
k = foo()
print(k)
A)
Error
B)
0
C)
1
D)
2

Correct Answer : Option (D) :   2

296 .
What will be the output of the following Python code?
 
try:
    if '1' != 1:
        raise "someError"
    else:
        print("someError has not occurred")
except "someError":
    print ("someError has occurred")
A)
someError has occurred
B)
someError has not occurred
C)
invalid code
D)
None of the above

Correct Answer : Option (C) :   invalid code

297 .
What happens when ‘1’ == 1 is executed?
A)
we get a True
B)
we get a False
C)
an TypeError occurs
D)
a ValueError occurs

Correct Answer : Option (B) :   we get a False

298 .
What will be the output of the following Python code?
 
lst = [1, 2, 3]
lst[3]
A)
NameError
B)
ValueError
C)
IndexError
D)
TypeError

Correct Answer : Option (C) :   IndexError

299 .
Compare the following two Python codes shown below and state the output if the input entered in each case is -6?
 
CODE 1
import math
num=int(input("Enter a number of whose factorial you want to find"))
print(math.factorial(num))
 
CODE 2
num=int(input("Enter a number of whose factorial you want to find"))
print(math.factorial(num))
A)
ValueError, NameError
B)
AttributeError, ValueError
C)
NameError, TypeError
D)
TypeError, ValueError

Correct Answer : Option (A) :   ValueError, NameError

300 .
What will be the output of the following Python code if the input entered is 6?
 
valid = False
while not valid:
    try:
        n=int(input("Enter a number"))
        while n%2==0:
            print("Bye")
        valid = True
    except ValueError:
        print("Invalid")
A)
No output
B)
Invalid (printed once)
C)
Bye (printed once)
D)
Bye (printed infinite number of times)

Correct Answer : Option (D) :   Bye (printed infinite number of times)