PYTHON QUIZ
1 .
Which of the following functions clears the regular expression cache?

Correct Answer : Option (D)

re.purge()
  Show Answer
2 .
Which of the following is a valid dictionary in Python?

Correct Answer : Option (B)

myExample = {‘someItem’: 2, ‘otherItem’: 20}
  Show Answer
3 .
What is the proper way to open a file that you intend to read from?

Correct Answer : Option (C)

f = open(“test.txt”, “r”)
  Show Answer
4 .
Which of the following lines of code will not show a match?

Correct Answer : Option (D)

>>> re.match(‘ab*’, ‘ba’)
  Show Answer
5 .
What is the output of the snippet of code shown below?
import turtle
t=turtle.Pen
t.tilt(75)
t.forward(100)‚Äč

Correct Answer : Option (C)

A straight line of 100 units lying along the horizontal
  Show Answer
6 .
What will be the output of the following Python code?
 
>>>"Welcome to Python".split()

Correct Answer : Option (A)

[“Welcome”, “to”, “Python”]
  Show Answer
7 .
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)

Correct Answer : Option (A)

1
  Show Answer
8 .
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 = " ")

Correct Answer : Option (C)

2 3 4 5 6 6
  Show Answer
9 .
What will be the output of the following Python code?
 
def f(values):
    values[0] = 44
 
v = [1, 2, 3]
f(v)
print(v)

Correct Answer : Option (D)

[44, 2, 3]
  Show Answer
10 .
What will be the output of the following Python code?
 
>>>m = [[x, x + 1, x + 2] for x in range(0, 3)]

Correct Answer : Option (B)

[[0, 1, 2], [1, 2, 3], [2, 3, 4]]
  Show Answer