Python Online Practice Test - 9

This Test will cover complete Python with very important questions, starting off from basics to advanced level.
Q. In an exam,developers were provided,the following code snippets:

for i in [61, 82, 23, 34][::-1]:
    print (i)

Mark the correct print outputs.
Q. In an exam,developers were provided,the following code snippets:

import operator

list1=[23,56,45,89]
list2 =operator.iadd(list1,[44,88])

print(list2)
print(list1)

Mark the correct answer.
Q. A peer,was explaining to his team,the concept of partial functions,in Python. He gave them the following example:

from functools import partial 

def partial_eg(first,second,third):
	return first* second* third
result = partial(partial_eg,5,8)
print(result(2))

Mark the correct answer.
Q. Developers were provided,the following statements,about Caching in Python,in an interview.They were asked to mark them as True or False:
  1. Using Memcached is a nice option,when the application system,is spread across a network.
  2. Python has a data structure lfu_cache,which uses least frequently used algorithm,to limit the cache size.
  3. If the memcached server goes down,the client keeps sending a request,till the time-out limit is reached.s
  4. We can use memcache,as a data store,as well as,a cache.
Choose the correct answer.

Q. A group of developers were involved,in a debate about Python 2 and 3 differences:
DevA- In Python3,there are two byte classes - the bytearray and byte.In Python2, there is no byte type present.Filter() and map() return lists in Python2.Python3 raises a SyntaxError, if exception arguments are not enclosed in parentheses.
DevB- In Python3, TypeError is raised as a warning,if unorderable types are compared.The same does not happens with Python2.Filter() returns a list in Python2 and Python3 version,but, map() returns the same, only in Python2.Python3 never raises a SyntaxError, if exception arguments are not enclosed in parentheses.
DevC- Both Python versions,have a byte type present.A bytearray type,is not present in Python2.In Python3 and Python2 version,map() returns a list,wheres filter() returns a list only in Python2.
Mark the correct output of the same.
Q. Consider the following code snippets:

def printUpper(text):
	return text.upper()
printUpper('namAste')
assignhere = printUpper
print(assignhere('Hello'))


def create_function(num1):
    def subtract_function(num2):
        return num1-num2 
    return subtract_function 
sub_var = create_function(45) 
print(sub_var(90))

Mark the correct output of the same.
Q. A developer was working with Numpy library. He was told,to create the following types of arrays:
  1. Create an 2x3 array, of complex type, with real value number 3.
  2. Create a 4x1 array,containing all zeros.
  3. Create a sequence of integers,from 0 to 25 with steps of 4.
Mark the appropriate syntax, to do the above.(NOTE: np is the numpy object)
Q. A lead was teaching his team,about the zipping files,in Python.He stated the following:
  1. The compression using the python zipfile is lossless.
  2. Python zipfile can also create encrypted files,or,handle multi-disk ZIP files.
  3. The Zipfile, creates just a single file that contains all the compressed files.
  4. Files that handle ZIP64 extensions, can be handled by the zipfile module.
Choose the right option.
Q. A developer was told,to provide a customised message('This key does not exists'),if any key that was searched,was not present in the dictionary. If the existing code was as follows:

import collections
dict_port = { 'pipavav' : 2316 , 'vizag' : 5242 }
print (dict_port['trivandrum'])

Mark the correct syntax,for implementing the message.

Q. In an interview, following code snippets were provided.(NOTE: Value of var = 45)

print(1 < var+10 < 10)


print(var < 80 < var*2 < 100)


print(10 > var <= 2)

Mark the correct Output.
Q. In an exam,following code snippets were provided:

def packlist(n1, n2, n3, n4):
    print(n1, n2, n3, n4) 
list_eg = [14, 62, 83, 24]
packlist(**list_eg)

Mark the correct answer.
Q. In an exam,following code snippets were provided-

def packlist(n1, n2, n3, n4):
    print(n1, n2, n3, n4) 
list_eg = [14, 62, 83, 24]
packlist(**list_eg)

Mark the correct answer.

Having second thoughts for any code related question?

Try executing the code in our Code Playground