Python Online Practice Test - 6

This Test will cover complete Python with very important questions, starting off from basics to advanced level.
Q.In an exam, the developers were provided,the following statements,regarding File copying,using system shell utilities:
a) The shutil.copy2() function, is same as shutil.copy(), except that copy2(),copies the file metadata,along with the file.
b) When using copy2() function, one must specify the file buffer.
c) The copy2() function,does not copies,the permission bits,to the destination file.
d) If we want an exact duplicate copy of a file, the copy() function,should be used,instead of copy2().
Mark them if they are appropriate as Yes or No.
Q. Below are mentioned,descriptions of Python file extensions:
a) Python script archive file.
b) Windows DLL file.
c) A python file created with optimizations.
d) The compiled bytecode of the file.
Mark them correctly with the actual file extensions.
Q. A developer was checking,her Python code,using Tabnanny utility tool. She knew,that tool helped,in checking ambiguous code.She was given,some points to check:
1) Analyse white-space related issues.
2) Code should print verbose messages.
3) Display names of files,that contain issues,related to whitespaces.
Which methods,of the tool should she use?
Mark the correct answer.
Q. In an exam,students were provided following code snippets:

#1
a=1 
if a<1:
	print("2") 
elif a<=1:
	print("3")
else:
	print("1")

#2
def div(firstnum,secondnum):
    assert secondnum!=0, "This is divide by zero"
    return firstnum/secondnum
div(23,0)


Mark the correct output.

Q. In an interview,a rapid fire round was conducted,where the freshers were told,to answer the questions,as Yes or No:
1) Atmost,only one else statement,can follow an if statement.
2) Python does not has a switch and case syntax.
3) By default,parameters are passed to its functions, using pass-by-reference.
4) Internally a namespace,is implemented as a dictionary, in Python.
Mark the correct answer.
Q. A group of developers,were involved in a debate,about methods and functions,in Python:
Dev A- A method is associated to a class object. It may or may not return any data.
Dev B- A function can be called,by its name,as well as,using the class object.A method should always return some data.
Dev C- A method is associated to a class object,whereas a function is not. Data parameters are passed implicitly to a function.
Mark the correct answer.
Q. A developer was working,on some f-strings code snippets. She was trying,to analyse,the output of the following:

#1
name="Alisa"
profession="Doctor"
regards_msg = f"Hello {name}. " \
			"Meet you soon {profession}. " 
print(regards_msg)
	    

#2
print(f"{34*2}")
	    

#3
author = "Enid Blyton"
books =f"author.lower() is amazing!"
print(books)


Mark the correct output.
Q. A lead was testing, his team's knowledge on lists. So he gave them,the following code snippet:

metals = ['gold','silver','copper']
metals[1:] = ['platinum','lead']
print(metals)
metals[2:3]=['bronze','tin']
print(metals)
metals[3:3]=['titanium']
print(metals)

Mark the correct output.
Q. Consider the following lambda expression:

#1
two_val = lambda num1: num1 * 2
three_val = lambda num1: num1 * 3
abc = 3
abc = two_val(abc)
abc = three_val(abc)
abc = two_val(abc)
print(abc)

#2
list_a=[2,4,5]
list_b=[6,5,4]
addlistelements = lambda list1,list2: list1 + list2
print(addlistelements(list_a,list_b))


Mark the correct answer.

Q. A developer had to mention,a few comparison points,regarding Scala and Python. He stated the following:
1) Performance wise Scala,is much better than Python.
2) Python is much simpler,than Scala.
3) For an application, which consists of a lot of concurrent processes,Python should be preferred.
4) Refactoring Scala code,is much easier,as compared to Python.
Mark them as True or False.

Having second thoughts for any code related question?

Try executing the code in our Code Playground