Python Test Questions
with Answers
What do the following lines of code do?
with open("Example2.txt","w") as writefile:
writefile.write("This is line A\n")
writefile.write("This is line B\n")
Read the file "Example2.txt"
Write to the file "Example2.txt"
Append the file "Example2.txt" - Answer-Write to the file "Example2.txt"
What do the following lines of code do?
with open("Example3.txt","a") as file1:
file1.write("This is line C\n")
Read the file "Example3.txt"
Write to the file "Example3.txt"
Append the file "Example3.txt" - Answer-Append the file "Example3.txt"
What is the result of applying the following method df.head(), to the dataframe df
prints the first row of the dataframe
prints the first column of the dataframe
prints the first 5 rows of the dataframe
prints the dateframe out - Answer-prints the first 5 rows of the dataframe
what is the result of the following lines of code:
a=np.array([0,1,0,1,0])
b=np.array([1,0,1,0,1])
a*b
0
array([1, 1, 1, 1, 1])
array([0, 0, 0, 0, 0]) - Answer-array([0, 0, 0, 0, 0])
what is the result of the following lines of code:
a=np.array([0,1])
b=np.array([1,0])
np.dot(a,b)
, 1
array([1,1])
0
array([0,0]) - Answer-0
what is the result of the following lines of code:
a=np.array([1,1,1,1,1])
a+10
array([10,10,10,10,10])
array([11, 11, 11, 11, 11])
array([1,1,1,1,1]) - Answer-array([11, 11, 11, 11, 11])
what is the correct code to perform matrix multiplication on the matrix A and B
np.dot(A,B)
A*B
AxB - Answer-np.dot(A,B)
What is the type of the following variable: a=True? - Answer-Bool
What is the result of the following operation int(3.2)? - Answer-3
Consider the string A='1234567', what is the result of the following operation: A[1::2] -
Answer-'246'
Consider the string Name="Michael Jackson" , what is the result of the following
operation Name.find('el') - Answer-5
The variables A='1' and B='2' ,what is the result of the operation A+B? - Answer-'12'
What is the result of the following operation in Python:
3+2*2
10
7
9
12 - Answer-7
In Python, if you executed name = 'Lizz', what would be the output of print(name[0:2])?
Lizz
L
Liz