MCQOPTIONS
Saved Bookmarks
This section includes 477 Mcqs, each offering curated multiple-choice questions to sharpen your Computer Science Engineering (CSE) knowledge and support exam preparation. Choose a topic below to get started.
| 101. |
)) type(g) |
| A. | class <’loop’> |
| B. | class <‘iteration’> |
| C. | class <’range’> |
| D. | class <’generator’> |
| Answer» E. | |
| 102. |
Which of the following is not an exception handling keyword in Python? |
| A. | try |
| B. | except |
| C. | accept |
| D. | finally |
| Answer» D. finally | |
| 103. |
What happens when ‘1’ == 1 is executed? |
| A. | we get a true |
| B. | we get a false |
| C. | an typeerror occurs |
| D. | a valueerror occurs |
| Answer» C. an typeerror occurs | |
| 104. |
When is the finally block executed? |
| A. | when there is no exception |
| B. | when there is an exception |
| C. | only if some condition that has been specified is satisfied |
| D. | always |
| Answer» E. | |
| 105. |
Which function overloads the // operator? |
| A. |     div    () |
| B. |     ceildiv    () |
| C. |     floordiv    () |
| D. |     truediv    () |
| Answer» D.     truediv    () | |
| 106. |
Which function overloads the >> operator? |
| A. |     more    () |
| B. |     gt    () |
| C. |     ge    () |
| D. | none of the mentioned |
| Answer» E. | |
| 107. |
How many except statements can a try- except block have? |
| A. | zero |
| B. | one |
| C. | more than one |
| D. | more than zero |
| Answer» E. | |
| 108. |
Which operator is overloaded by     lg    ()? |
| A. | < |
| B. | > |
| C. | != |
| D. | none of the mentioned |
| Answer» E. | |
| 109. |
Which function overloads the == operator? |
| A. |     eq    () |
| B. |     equ    () |
| C. |     isequal    () |
| D. | none of the mentioned |
| Answer» B.     equ    () | |
| 110. |
Which function overloads the + operator? |
| A. |     add    () |
| B. |     plus    () |
| C. |     sum    () |
| D. | none of the mentioned |
| Answer» B.     plus    () | |
| 111. |
What happens if no arguments are passed to the seek function? |
| A. | file position is set to the start of file |
| B. | file position is set to the end of file |
| C. | file position remains unchanged |
| D. | error |
| Answer» E. | |
| 112. |
How do you change the file position to an offset value from the start? |
| A. | fp.seek(offset, 0) |
| B. | fp.seek(offset, 1) |
| C. | fp.seek(offset, 2) |
| D. | none of the mentioned |
| Answer» B. fp.seek(offset, 1) | |
| 113. |
How do you rename a file? |
| A. | fp.name = ‘new_name.txt’ |
| B. | os.rename(existing_name, new_name) |
| C. | os.rename(fp, new_name) |
| D. | os.set_name(existing_name, new_name) |
| Answer» C. os.rename(fp, new_name) | |
| 114. |
How do you delete a file? |
| A. | del(fp) |
| B. | fp.delete() |
| C. | os.remove(‘file’) |
| D. | os.delete(‘file’) |
| Answer» D. os.delete(‘file’) | |
| 115. |
How do you get the current position within the file? |
| A. | fp.seek() |
| B. | fp.tell() |
| C. | fp.loc |
| D. | fp.pos |
| Answer» C. fp.loc | |
| 116. |
How do you close a file object (fp)? |
| A. | close(fp) |
| B. | fclose(fp) |
| C. | fp.close() |
| D. | fp.    close    () |
| Answer» D. fp.    close    () | |
| 117. |
How do you get the name of a file from a file object (fp)? |
| A. | fp.name |
| B. | fp.file(name) |
| C. | self.    name    (fp) |
| D. | fp.    name    () |
| Answer» B. fp.file(name) | |
| 118. |
What is the difference between r+ and w+ modes? |
| A. | no difference |
| B. | in r+ the pointer is initially placed at the beginning of the file and the pointer is at the end for w+ |
| C. | in w+ the pointer is initially placed at the beginning of the file and the pointer is at the end for r+ |
| D. | depends on the operating system |
| Answer» C. in w+ the pointer is initially placed at the beginning of the file and the pointer is at the end for r+ | |
| 119. |
Which of the following are the modes of both writing and reading in binary format in file? |
| A. | wb+ |
| B. | w |
| C. | wb |
| D. | w+ |
| Answer» B. w | |
| 120. |
Which function is used to close a file in python? |
| A. | close() |
| B. | stop() |
| C. | end() |
| D. | closefile() |
| Answer» B. stop() | |
| 121. |
Which function is used to write a list of string in a file? |
| A. | writeline() |
| B. | writelines() |
| C. | writestatement() |
| D. | writefullline() |
| Answer» B. writelines() | |
| 122. |
Is it possible to create a text file in python? |
| A. | yes |
| B. | no |
| C. | machine dependent |
| D. | all of the mentioned |
| Answer» B. no | |
| 123. |
Which function is used to write all the characters? |
| A. | write() |
| B. | writecharacters() |
| C. | writeall() |
| D. | writechar() |
| Answer» B. writecharacters() | |
| 124. |
Which function is used to read single line from file? |
| A. | readline() |
| B. | readlines() |
| C. | readstatement() |
| D. | readfullline() |
| Answer» C. readstatement() | |
| 125. |
Which function is used to read all the characters? |
| A. | read() |
| B. | readcharacters() |
| C. | readall() |
| D. | readchar() |
| Answer» B. readcharacters() | |
| 126. |
What is the use of “a†in file handling? |
| A. | read |
| B. | write |
| C. | append |
| D. | none of the mentioned |
| Answer» D. none of the mentioned | |
| 127. |
What is the use of “w†in file handling? |
| A. | read |
| B. | write |
| C. | append |
| D. | none of the mentioned |
| Answer» C. append | |
| 128. |
In file handling, what does this terms means “r, a� |
| A. | read, append |
| B. | append, read |
| C. | write, append |
| D. | none of the mentioned |
| Answer» B. append, read | |
| 129. |
Correct syntax of file.writelines() is? |
| A. | file.writelines(sequence) |
| B. | fileobject.writelines() |
| C. | fileobject.writelines(sequence) |
| D. | none of the mentioned |
| Answer» D. none of the mentioned | |
| 130. |
What is the correct syntax of open() function? |
| A. | file = open(file_name [, access_mode][, buffering]) |
| B. | file object = open(file_name [, access_mode][, buffering]) |
| C. | file object = open(file_name) |
| D. | none of the mentioned |
| Answer» C. file object = open(file_name) | |
| 131. |
What is unpickling? |
| A. | it is used for object serialization |
| B. | it is used for object deserialization |
| C. | none of the mentioned |
| D. | all of the mentioned |
| Answer» C. none of the mentioned | |
| 132. |
What is the pickling? |
| A. | it is used for object serialization |
| B. | it is used for object deserialization |
| C. | none of the mentioned |
| D. | all of the mentioned |
| Answer» B. it is used for object deserialization | |
| 133. |
Which of the following mode will refer to binary data? |
| A. | r |
| B. | w |
| C. | + |
| D. | b |
| Answer» E. | |
| 134. |
sys.stdout.write('Python\n') |
| A. | compilation error |
| B. | runtime error |
| C. | hello python |
| D. | hello python |
| Answer» E. | |
| 135. |
print 'Your name is:', name |
| A. | sanfoundry |
| B. | sanfoundry, sanfoundry |
| C. | san |
| D. | none of the mentioned |
| Answer» B. sanfoundry, sanfoundry | |
| 136. |
What is the use of truncate() method in file? |
| A. | truncates the file size |
| B. | deletes the content of the file |
| C. | deletes the file size |
| D. | none of the mentioned |
| Answer» B. deletes the content of the file | |
| 137. |
What is the use of seek() method in files? |
| A. | sets the file’s current position at the offset |
| B. | sets the file’s previous position at the offset |
| C. | sets the file’s current position within the file |
| D. | none of the mentioned |
| Answer» B. sets the file’s previous position at the offset | |
| 138. |
What is the current syntax of remove() a file? |
| A. | remove(file_name) |
| B. | remove(new_file_name, current_file_name,) |
| C. | remove(() , file_name)) |
| D. | none of the mentioned |
| Answer» B. remove(new_file_name, current_file_name,) | |
| 139. |
What is the current syntax of rename() a file? |
| A. | rename(current_file_name, new_file_name) |
| B. | rename(new_file_name, current_file_name,) |
| C. | rename(()(current_file_name, new_file_name)) |
| D. | none of the mentioned |
| Answer» B. rename(new_file_name, current_file_name,) | |
| 140. |
fo.close() |
| A. | compilation error |
| B. | syntax error |
| C. | displays output |
| D. | none of the mentioned |
| Answer» D. none of the mentioned | |
| 141. |
What is the use of tell() method in python? |
| A. | tells you the current position within the file |
| B. | tells you the end position within the file |
| C. | tells you the file is opened or not |
| D. | none of the mentioned |
| Answer» B. tells you the end position within the file | |
| 142. |
Which one of the following is not attributes of file? |
| A. | closed |
| B. | softspace |
| C. | rename |
| D. | mode |
| Answer» D. mode | |
| 143. |
Which are the two built-in functions to read a line of text from standard input, which by default comes from the keyboard? |
| A. | raw_input & input |
| B. | input & scan |
| C. | scan & scanner |
| D. | scanner |
| Answer» B. input & scan | |
| 144. |
print(f.closed) |
| A. | true |
| B. | false |
| C. | none |
| D. | error |
| Answer» B. false | |
| 145. |
To read the remaining lines of the file from a file object infile, we use |
| A. | infile.read(2) |
| B. | infile.read() |
| C. | infile.readline() |
| D. | infile.readlines() |
| Answer» E. | |
| 146. |
1 TEXT FILES, READING AND WRITING FILES, FORMAT OPERATOR |
| A. | infile.read(2) |
| B. | infile.read() |
| C. | infile.readline() |
| D. | infile.readlines() |
| Answer» B. infile.read() | |
| 147. |
To open a file c:\scores.txt for appending data, we use |
| A. | outfile = open(“c:\\scores.txtâ€, “aâ€) |
| B. | outfile = open(“c:\\scores.txtâ€, “rwâ€) |
| C. | outfile = open(file = “c:\\scores.txtâ€, “wâ€) |
| D. | outfile = open(file = “c:\\scores.txtâ€, “wâ€) |
| Answer» B. outfile = open(“c:\\scores.txtâ€, “rwâ€) | |
| 148. |
To open a file c:\scores.txt for writing, we use |
| A. | outfile = open(“c:\\scores.txtâ€, “wâ€) |
| B. | outfile = open(“c:\\scores.txtâ€, “wâ€) |
| C. | outfile = open(file = “c:\\scores.txtâ€, “wâ€) |
| D. | outfile = open(file = “c:\\scores.txtâ€, “wâ€) |
| Answer» C. outfile = open(file = “c:\\scores.txtâ€, “wâ€) | |
| 149. |
To open a file c:\scores.txt for reading, we use |
| A. | infile = open(“c:\\scores.txtâ€, “râ€) |
| B. | infile = open(“c:\\scores.txtâ€, “râ€) |
| C. | infile = open(file = “c:\\scores.txtâ€, “râ€) |
| D. | infile = open(file = “c:\\scores.txtâ€, “râ€) |
| Answer» C. infile = open(file = “c:\\scores.txtâ€, “râ€) | |
| 150. |
If b is a dictionary, what does any(b) do? |
| A. | returns true if any key of the dictionary is true |
| B. | returns false if dictionary is empty |
| C. | returns true if all keys of the dictionary are true |
| D. | method any() doesn’t exist for dictionary |
| Answer» B. returns false if dictionary is empty | |