Font size
WorksheetsPython Mix Quiz
Total questions: 64
Worksheet time: 32mins
What will the following code result in?
True
[9, 7, 5, 3, 1]
False
[9, 7, 5, 3, 1]
True
[1, 3, 5, 7, 9]
None of the above
Predict the output:
1
2
[13, 18, 11, 16, 13, 18, 13, 2]
0
2
[13, 18, 11, 16, 13, 18, 13, 3]
5
2
[13, 18, 11, 16, 13, 18, 13, 3]
1
2
[13, 18, 11, 16, 13, 18, 13, 3]
Given two lists, which of the following statements will cause an error?
L1==L2
L1.upper()
L1[3].upper()
L2[1][1].upper()
Out of the following, what is correct syntax to copy one list into another?
listA=listB[]
listA=listB[:]
listA=listB[]()
listA=list(listB)
What is the output when we execute list("hello")?
['h','e','l','l','o']
['hello']
['llo']
['olleh']
What gets printed?
H
a
Hasan
Dia
Which of the following statements will create a tuple?
tp1=("a","b")
tp1[2]=("a","b")
tp1=(3)*3
None of these
What will be the output of following Python code?
(15,11,16,12)
(15,11,17,16)
(15,11,17,16,12)
Error
Which of the following options will not result in an error when performed on types in Python where tp=(5,2,7,0,3)?
tp[1]=2
tp.append(2)
tp1=tp+tp
tp.sum()
What is the length of the tuple t=(((('a',1),'b','c'),'d',2),'e',3) ?
1
2
3
4
What will be stored in variables 'a' after following statements?
perc=(88,85,80,88,83,86)
a=perc[2:-2]
(80,88)
(80,88,83)
(88,80)
(83,88,80)
Carefully read the given code fragments and figure out the errors that the code may produce.
t5=t3*(3)
t4=t3*3
t3=(6,7)
t6=t3*(3,)
Predict the output :-
3
2
False
3
2
2
2
False
3
3
3
3
False
2
2
2
3
False
2
3
What will be the output of the following code snippet?
Tup1=((1,2),)*7
print(len(Tup1[3:8]))
2
3
4
5
Find the output generated by the code fragment :
plane=("Passengers","Luggage")
plane[1]="Snakes"
plane=("Passengers","Snakes")
plane=("Passengers","Snakes","Luggage")
plane=("Snakes","Passengers","Luggage")
Error
What is the output of the following code?
[0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 48]
[4, 8, 16, 20, 28, 32, 40, 44]
[0, 12, 24, 36, 48]
None of the above
Find the error :
L1=[1,11,21,31]
An=L1.remove(41)
(a) Value error : 41 not in list
(b) remove() doesn't return any value
(c) remove() function is not applicable on lists
(d) both (a) & (b)
Given a list L1=[3,4.5,12,25.7,[2,1,0,5],88], which function can change the list to [3,4.5,12,25.7,88]?
del L1[4]
L1.pop(4)
L1.pop(-2)
All the above
Write the output of the following code:
>>> L=[“Amit”,”Anita”,”Zee”,”Longest Word”,123]
>>> print(max(L))
Longest Word
Zee
Amit
Error
Write the output of the following code :
>>>L=[1,2,3,4,5,[6,7,8]]
>>>print(L[5])
[6, 7, 8]
6, 7, 8
Error
6
(a) is smallest individual unit in a program.
Choose the INVALID identifiers from the following
NUmbEr1
1NUMBer
A_B
A&B
________ are data items that have a fixed value
Tokens
Literals
Keyword
Operators
Examples of String Literals
"ABC1273"
nfjdlsj@@$
12638
'7e920938'
Escape sequence is represented by a ____ followed by one or more characters
Front slash
Double Quote
Single Quote
Back Slash
Size of the string "Ant Man"
(a)
str="Red\
block\
a"
Size of str is 11. True/False ?
True
False
Select the valid Octal integer literals
0836
7976
07362
0x1726
An escape sequence represents how many characters ?
"\t"
3
2
1
4
(a) is a special literal used to indicate something has not yet been created. It also indicates the end of lists in Python.
Which of the following is a Boolean literal ?
True
false
False
true
+, /, * are example of which token ?
This token triggers some computation
(a)
What will be the output-
f=open('abc.txt','a')
text="xyz"
f.write(text)
f.close()
Writing into the file without erasing old content
Writing into the file by erasing old content
reading from the file without erasing old content
reading from the file by erasing old content
Mode in the following program to open file for writing in a mode where new data will be added at the end of old data
file =open("poem.txt","__")
r
w
a
r+
Choose the correct statement to close a file stream named myfile:
myfile.terminate()
myfile.end()
myfile.close()
myfile.remove()
Fill in the blank with appropriate statement.
(a)
Write the appropriate statement in the blank.
(a)
Which statement(s) is/are true to open a binary file "Record.dat" for reading and writing.
file =open("Record.dat","wb")
file =open("Record.dat","rb")
file =open("Record.dat","ab")
file =open("Record.dat","rb+")
Which function read single line at a time?
read()
read(n)
readline()
readlines()
Which file is not binary file?
student.mp4
student.jpeg
student.csv
student.exe
Where files are store permanently?
RAM
Hard Disk
Cache memory
None of these
Which function is used to write multiple lines in text file?
write()
writelines()
lines()
print()
Which statement(s) is/are true to open a binary file "Record.dat" for reading and writing ?
file =open("Record.dat","wb")
file =open("Record.dat","rb")
file =open("Record.dat","ab")
file =open("Record.dat","rb+")
Q.2 Which of the following statements are not true regarding the opening modes of a file?
When you open a file for reading, if the file does not exist, an error occurs.
When you open a file for writing, if the file does not exist, an error occurs
When you open a file for writing, if the file does not exist, a new file is created.
When you open a file for writing, if the file exists, the existing file is overwritten with the new file.
Q.3 Which module is used to work with binary files?
CSV module
pickle module
math module
binary module
Q.5 'try' block is used to
execute a code
through the exceptions
to try some random code
to give errors
Function used to write data in binary format
write()
output()
load()
dump()
What is the use of “a” in file handling?
Read
Write
Append
None of the mentioned
