Signup/Sign In

Python Online Practice Test - 12

This Test will cover complete Python with very important questions, starting off from basics to advanced level.
Q. A developer was working on following code snippets:

examplestr="learn"
for i in range(len(examplestr)):
    print (examplestr)
    examplestr = '1'


testlist = [True, 34, 23]
testlist.insert(2, 7)    
print("Add is: ", sum(testlist)) 

Mark the correct print outputs.
Q. A lead was explaining,to his team,the concept of coroutines,in Python:
  1. Coroutines can be chained together,and, data can be sent through pipes, using the send() method.Thus they can be used to set pipes.
  2. When a coroutine is not closed, it generates a GeneratorExit exception.
  3. If we try to send values, after a coroutine is closed,it throws a StopGeneration exception.
  4. A coroutine runs when it is called. It also runs in response to the next() method.
Mark the correct statement.
Q. A developer wrote the following code snippets,while trying list and dictionary comparisons:

my_tuple = (6, 2, 0, 0)
my_tuple1 = (5, 2, 3, 4)
print(my_tuple > my_tuple1)


d1 = {"john":430, "peter":55}
d2 = {"john":466, "peter":45}
print(d1 > d2)

Mark the correct answer.
Q. A lead was explaining to his team, the concept of Closure function.He stated the following:
  1. They help to reduce,the use of global variables.
  2. They help in data hiding, so they are used as callback functions.
  3. They do not allow,to invoke functions,outside their scope.
  4. They are efficient,when multiple functions,are needed in the code.
Choose the correct answer.

Q.In an exam the following statements were provided:
  1. Modifying a class or module,at run-time,dynamically,is called monkey-patching.
  2. The os.unlink command,can be used to delete a file in Python.
  3. The lambda form in Python,has many statements,as they make new function object.
  4. Generators are a way of implementing iterators.
Mark them as True or False.
Q. A developer was working on code of NamedTuple in a Python application. Consider his code below:

from collections import namedtuple
Cities=namedtuple('Cities','Delhi Mumbai Chennai')
Delhi=Cities(Delhi=11,Mumbai=0,Chennai=0)
Mumbai=Cities(Delhi=0,Mumbai=22,Chennai=0)
Chennai=Cities(Delhi=0,Mumbai=0,Chennai=44)

Mark the correct statement.
Q. In an exam, developers were told to mark,the output of code snippets,provided below:

listone = [94,78,23,12,45]
listone.append([23,90])
print(len(listone))


list1=[45,33,90]
list2=[34,56,8]
print(list1-list2)



import re
print(re.sub('re', '^^', 'REd reD Riding'))


Choose the correct answer-
Q. Developers were told to identify,some python modules,based on the following descriptions:
  1. Allows to create and manipulate C data types.
  2. Helps in extracting,formatting and printing of stack traces.
  3. Supports working with important iterables.
Mark the appropriate answer.

Q. Consider the following code snippets:

def testdict():
	strdict=dict()
	strdict['abc']=456
	strdict['xyz']=888	
	return strdict
print(testdict())



def testlist():
	list1="this is a list"
	list2="yes a list"
	return [list1,list2]
print(testlist())


Mark the incorrect statement.
Q. In an exam, freshers were told to mark the statements as True or False:
  1. The CGI module is used for creating forms in Python.
  2. The enumerate() function in Python,gives,the index position and the corresponding value present in a sequence
  3. If string str="Country is", then the syntax print(str._len_()) is an optimal way of printing the length of the string.
  4. The type(xyz) where xyz=(1) gives the output as 'tuple'.
Mark the correct answer.