Hurry! Try our new Interactive Courses for FREE. 🥳   🚀

Python Online Practice Test - 11

This Test will cover complete Python with very important questions, starting off from basics to advanced level.
Q. In a technical competition,following code snippet was given:

def area(a):
	return a*a
def area(a,b):
	return a*b	
print(area(12))
print(area(14,5))

Mark the correct print outputs.
Q. In an exam, following code snippet was provided:

def tree_name():
	name = "coconut"
	def tree_use():
		nonlocal name
		name="banyan"
		print(name)
	tree_use()
	print(name)
tree_name()

Mark the correct output of the above.
Q. A developer,was asked to guess the output of the following code snippet:

class Aa:
                id=11        
class Bb:
                id=22             
class Cc:
                id=33              
class Xx(Cc,Bb,Aa):
                pass
print(Xx.id)

Mark the correct answer.
Q. A developer was told to explain to his team,the concept of docstring in Python. He stated the following:
  1. A program can examine descriptions,at run time,like as metadata,if the functions are provided with docstrings.
  2. Docstrings can be accessed by .doc attribute on objects.
  3. A comment is not retained at runtime,but a docstring is.
  4. A docstring line,should begin with a capital letter,and,end with a period.
Choose the correct answer.

Q. A group of developers,were involved in a debate,about Python Generators and Iterators.
Dev A- Writing generator code is fast , easy and compact.A generator can contain,any number of "yield" statements.Python iterator,is less memory efficient.
Dev B- Iterators,are more memory efficient,than generators.Both of them,can have any number of "yield" statements.Iterator cannot be created,using Python class,while ,a generator can be.
Dev C- An iterator never makes use of "yield" statements.It can be created using Python class. Even a generator may need a class in Python.
Mark the correct option.
Q. A fresher was asked to explain,the concept of frozen set,in Python. He stated the following:
  1. After creation,the elements of a frozen set,remain the same.
  2. Frozen sets are just as ordered as any Set.
  3. Frozen sets perform,limited operations,as compared to normal sets,since they are frozen.Example union,intersection etc cannot be executed with them.
  4. Frozen sets can be used as a key in Dictionary.
Mark if the above are Right or Wrong.
Q. A lead was testing the knowledge of his freshers team in Python. He provided them some random code snippets:

print((11,34)+(24,57))


stooges_names = "{2}, {0} and {1}".format('Moe', 'Larry', 'Curley')
print(stooges_names)


cubes = {1:1, 2:8, 3:27, 4:64, 5:125}  
print(cubes.pop(2))  

Mark the appropriate syntax, to do the above.(NOTE: np is the numpy object)
Q. In an exam, the freshers were given the following code regarding the Matrices:

ports = [['Pipavav',180,190,395],
     ['Vizag',375,585,300],
     ['Karwar',580,690,495]]	
print(ports[-3]) 	
print(ports[-3][-2])
print(ports[-1][3])

Mark the appropriate answer.

Q. A developer was explaining his peer,about using the 'pass' keyword in Python:
Mark the incorrect statement.
Q. In a quiz, following points were mentioned,about Python file writing modes:
  1. The 'a+' mode,opens a file,for reading and appending data.If the file does not exists, it throws an error
  2. The 'wb' mode,opens a file for writing only in binary format.It overwrites the file,if it already exists.
  3. In 'ab' mode, the file is opened,for appending data. The file pointer,is at the start of the file, since it is in binary format.
  4. The 'w+' mode, opens the file,for writing as well as reading.It creates a new file for the same if it does not exists.
Mark them as correct(C) or Incorrect(In).