Signup/Sign In

Python Online Practice Test - 10

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

def sum(abc=1,xyz):
	return abc+xyz
sum(41)


def hello(hellotext):
	print(hellotext,"namaste")
hello('Hello is same as')

Mark the correct print outputs.
Q. A developer wrote the following code snippet:

def main():
	print ("This is the main function")
print ("Lets call print from main")

The output desired was -
This is the main function
Lets call print from main
But he was not getting it. Which of the following options,should be applied?
Q. Below are given a few scenarios. He gave them the following example :

class House:
	pass
print(House.area)


dict_eg={1:1,2:2}
dict_eg[3]


import maths

Mark the correct answer.
Q. In an interview,a fresher was given the following code snippet:

flavors=['mango','butterscotch','strawberry']
flavors[2:]=['chocolate','almond','vanilla']
print(flavors)


multi=[[[11,21],[31,41],51],[61,71]]
print(multi[0][1][1])

Choose the correct answer.

Q. Below are mentioned a few key points:
  1. Mainly used for data analysis,graphical models , statistics etc.
  2. Most of its code is slow.
  3. Ease of preparation,of new models,like matrix computation etc.
  4. It gets integrated with applications efficiently.
Mark,which language has a dominance,in the above points (R or Python)
Q. A developer was practicing some code snippets. He came across the following:

import nltk

from nltk.stem import PorterStemmer

examplewords=['waiting','waits','awaits','waited']
ps=PorterStemmer()

for word in examplewords:
	print(f"{word}: {ps.stem(word)}")

Mark the correct output of the same.
Q. In an exam,following code snippets, were provided:

import re

rhyme = """twinkle
twinkle
little"""
result2 = re.findall(r"^\w", rhyme, re.MULTILINE)

print(result2)


import re

match=re.search('^\w*nts','All tennis tournaments?')
print(match.group())

Mark the appropriate syntax, to do the above.(NOTE: np is the numpy object).
Q. In an exam,developers were given a few descriptions,about Python compilers and interpreters:
  1. With this compiler, Python scripts can interact with .NET objects.
  2. We can run the python code,on any machine,that has JVM,because of this compiler.We can also extend Java classes.
  3. With this framework,one can develop, client-side web applications,that can run in a browser.
Mention the names that map to them. Mark the appropriate answer.

Q. Below are given a few statements,about the Python main function:
  1. Python sets,special variable(__name__) to have value (__main__), when source file is run as a main program.
  2. Python modules can be used as standalone programs,because of "if__name__== "__main__". But they cannot be treated as reusable modules.
  3. When the main function is executed, interpreter will read the "if" statement,and,check if __name__ is equal to __main__.
  4. It is important to take care of indentation,after declaring the main function,else,one can get an Indentation error.
Mark them as Valid(V) or Invalid(In).
Q. A lead was explaining to his team,theory about Python memory management. Below are a few mentioned points:
  1. A private heap space manages the memory in Python.It is the place where all objects and data structures,are located.
  2. Python memory manager,allocates space,for python objects on the heap
  3. Python is unique,as its interpreter allows a programmer some access to the private heap.
  4. There is a inbuilt garbage collector,that recycles unused memory,and,makes it available to the heap.
Mark which of them are True or False.

Related Tests: