McqMate
Chapters
101. |
Suppose list1 is [3, 4, 5, 20, 5, 25, 1, 3], what is list1 after list1.reverse()? |
A. | [3, 4, 5, 20, 5, 25, 1, 3] |
B. | [1, 3, 3, 4, 5, 5, 20, 25] |
C. | [25, 20, 5, 5, 4, 3, 3, 1] |
D. | [3, 1, 25, 5, 20, 5, 4, 3] |
Answer» D. [3, 1, 25, 5, 20, 5, 4, 3] | |
Explanation: execute in the shell to verify. |
102. |
>>>"Welcome to Python".split() |
A. | [“welcome”, “to”, “python”] |
B. | (“welcome”, “to”, “python”) |
C. | {“welcome”, “to”, “python”} |
D. | “welcome”, “to”, “python” |
Answer» A. [“welcome”, “to”, “python”] | |
Explanation: split() function returns the elements in a list. |
103. |
>>>list("a#b#c#d".split('#')) |
A. | [‘a’, ‘b’, ‘c’, ‘d’] |
B. | [‘a b c d’] |
C. | [‘a#b#c#d’] |
D. | [‘abcd’] |
Answer» A. [‘a’, ‘b’, ‘c’, ‘d’] | |
Explanation: execute in the shell to verify. |
104. |
>>>print(indexOfMax) |
A. | 1 |
B. | 2 |
C. | 3 |
D. | 4 |
Answer» A. 1 | |
Explanation: first time the highest number is encountered is at index 1. |
105. |
numbers = [1, 2, 3, 4]
|
A. | 4 |
B. | 5 |
C. | 8 |
D. | 12 |
Answer» B. 5 | |
Explanation: a list is passed in append so the length is 5. |
106. |
To which of the following the “in” operator can be used to check if an item is in it? |
A. | lists |
B. | dictionary |
C. | set |
D. | all of the mentioned |
Answer» D. all of the mentioned | |
Explanation: in can be used in all data structures. |
107. |
>>>m = [[x, x + 1, x + 2] for x in range(0, 3)] |
A. | [[1, 2, 3], [4, 5, 6], [7, 8, 9]] |
B. | [[0, 1, 2], [1, 2, 3], [2, 3, 4]] |
C. | [1, 2, 3, 4, 5, 6, 7, 8, 9] |
D. | [0, 1, 2, 1, 2, 3, 2, 3, 4] |
Answer» B. [[0, 1, 2], [1, 2, 3], [2, 3, 4]] | |
Explanation: execute in the shell to verify. |
108. |
m = [[x, y] for x in range(0, 4) fo r y in range(0, 4)] |
A. | 8 |
B. | 12 |
C. | 16 |
D. | 32 |
Answer» C. 16 | |
Explanation: execute in the shell to verify. |
109. |
Which of the following is the same as list(map(lambda x: x**-1, [1, 2, 3]))? |
A. | [x**-1 for x in [(1, 2, 3)]] |
B. | [1/x for x in [(1, 2, 3)]] |
C. | [1/x for x in (1, 2, 3)] |
D. | error |
Answer» C. [1/x for x in (1, 2, 3)] | |
Explanation: x**-1 is evaluated as (x)**(-1). |
110. |
Write the list comprehension to pick out only negative integers from a given list ‘l’. |
A. | [x<0 in l] |
B. | [x for x<0 in l] |
C. | [x in l for x<0] |
D. | [x for x in l if x<0] |
Answer» D. [x for x in l if x<0] | |
Explanation: to pick out only the negative numbers from a given list ‘l’, the correct list comprehension statement would be: [x for x in l if x<0]. |
111. |
=[x+y for x, y in zip(l1, l2)] l3 |
A. | error |
B. | 0 |
C. | [-20, -60, -80] |
D. | [0, 0, 0] |
Answer» D. [0, 0, 0] | |
Explanation: the code shown above returns x+y, for x belonging to the list l1 and y belonging to the list l2. that is, l3=[10-10, 20-20, 30-20], which is, [0, 0, 0]. |
112. |
Write a list comprehension for number and its cube for l=[1, 2, 3, 4, 5, 6, 7, 8, 9]. |
A. | [x**3 for x in l] |
B. | [x^3 for x in l] |
C. | [x**3 in l] |
D. | [x^3 in l] |
Answer» A. [x**3 for x in l] | |
Explanation: the list comprehension to print |
113. |
Write a list comprehension for producing a list of numbers between 1 and 1000 that are divisible by 3. |
A. | [x in range(1, 1000) if x%3==0] |
B. | [x for x in range(1000) if x%3==0] |
C. | [x%3 for x in range(1, 1000)] |
D. | [x%3=0 for x in range(1, 1000)] |
Answer» B. [x for x in range(1000) if x%3==0] | |
Explanation: the list comprehension [x for x in range(1000) if x%3==0] produces a list of numbers between 1 and 1000 that are divisible by 3. |
114. |
Write a list comprehension to produce the list: [1, 2, 4, 8, 16……212]. |
A. | [(2**x) for x in range(0, 13)] |
B. | [(x**2) for x in range(1, 13)] |
C. | [(2**x) for x in range(1, 13)] |
D. | [(x**2) for x in range(0, 13)] |
Answer» A. [(2**x) for x in range(0, 13)] | |
Explanation: the required list comprehension will print the numbers from 1 to 12, each raised to 2. the required answer is thus, [(2**x) for x in range(0, 13)]. |
115. |
What is the data type of (1)? |
A. | tuple |
B. | integer |
C. | list |
D. | both tuple and integer |
Answer» B. integer | |
Explanation: a tuple of one element must be created as (1,). |
116. |
What type of data is: a=[(1,1),(2,4),(3,9)]? |
A. | array of tuples |
B. | list of tuples |
C. | tuples of lists |
D. | invalid type |
Answer» B. list of tuples | |
Explanation: the variable a has tuples enclosed in a list making it a list of tuples. |
117. |
Is the following Python code valid? >>> a,b=1,2,3 |
A. | yes, this is an example of tuple unpacking. a=1 and b=2 |
B. | yes, this is an example of tuple unpacking. a=(1,2) and b=3 |
C. | no, too many values to unpack |
D. | yes, this is an example of tuple unpacking. a=1 and b=(2,3) |
Answer» C. no, too many values to unpack | |
Explanation: for unpacking to happen, the number of values of the right hand side must be equal to the number of variables on the left hand side. |
118. |
Tuples can’t be made keys of a dictionary. |
A. | true |
B. | false |
Answer» B. false | |
Explanation: tuples can be made keys of a dictionary because they are hashable. |
119. |
Which of the following statements create a dictionary? |
A. | d = {} |
B. | d = {“john”:40, “peter”:45} |
C. | d = {40:”john”, 45:”peter”} |
D. | all of the mentioned |
Answer» D. all of the mentioned | |
Explanation: dictionaries are created by specifying keys and values. |
120. |
Suppose d = {“john”:40, “peter”:45}, to delete the entry for “john” what command do we use? |
A. | d.delete(“john”:40) |
B. | d.delete(“john”) |
C. | del d[“john”] |
D. | del d(“john”:40) |
Answer» C. del d[“john”] | |
Explanation: execute in the shell to verify. |
121. |
Suppose d = {“john”:40, “peter”:45}. To obtain the number of entries in dictionary which command do we use? |
A. | d.size() |
B. | len(d) |
C. | size(d) |
D. | d.len() |
Answer» B. len(d) | |
Explanation: execute in the shell to verify. |
122. |
print(list(d.keys())) |
A. | [“john”, “peter”] |
B. | [“john”:40, “peter”:45] |
C. | (“john”, “peter”) |
D. | (“john”:40, “peter”:45) |
Answer» A. [“john”, “peter”] | |
Explanation: the output of the code shown above is a list containing only keys of the dictionary d, in the form of a list. |
123. |
Which of these about a dictionary is false? |
A. | the values of a dictionary can be accessed using keys |
B. | the keys of a dictionary can be accessed using values |
C. | dictionaries aren’t ordered |
D. | dictionaries are mutable |
Answer» B. the keys of a dictionary can be accessed using values | |
Explanation: the values of a dictionary can be accessed using keys but the keys of a dictionary can’t be accessed using values. |
124. |
Which of the following is not a declaration of the dictionary? |
A. | {1: ‘a’, 2: ‘b’} |
B. | dict([[1,”a”],[2,”b”]]) |
C. | {1,”a”,2”b”} |
D. | { } |
Answer» C. {1,”a”,2”b”} | |
Explanation: option c is a set, not a dictionary. |
125. |
Which of the following isn’t true about dictionary keys? |
A. | more than one key isn’t allowed |
B. | keys must be immutable |
C. | keys must be integers |
D. | when duplicate keys encountered, the last assignment wins |
Answer» C. keys must be integers | |
Explanation: keys of a dictionary may be any data type that is immutable. |
126. |
Which of the statements about dictionary values if false? |
A. | more than one key can have the same value |
B. | the values of the dictionary can be accessed as dict[key] |
C. | values of a dictionary must be unique |
D. | values of a dictionary can be a mixture of letters and numbers |
Answer» C. values of a dictionary must be unique | |
Explanation: more than one key can have the same value. |
127. |
If a is a dictionary with some key-value pairs, what does a.popitem() do? |
A. | removes an arbitrary element |
B. | removes all the key-value pairs |
C. | removes the key-value pair for the key given as an argument |
D. | invalid method for dictionary |
Answer» A. removes an arbitrary element | |
Explanation: the method popitem() removes a random key-value pair. |
128. |
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» A. returns true if any key of the dictionary is true | |
Explanation: method any() returns true if any key of the dictionary is true and false if the dictionary is empty. |
129. |
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» B. outfile = open(“c:\\scores.txt”, “w”) | |
Explanation: w is used to indicate that file is to be written to. |
130. |
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» A. outfile = open(“c:\\scores.txt”, “a”) | |
Explanation: a is used to indicate that data is to be appended. |
131. |
Which of the following statements are true? |
A. | when you open a file for reading, if the file does not exist, an error occurs |
B. | when you open a file for writing, if the file does not exist, a new file is created |
C. | when you open a file for writing, if the file exists, the existing file is overwritten with the new file |
D. | all of the mentioned |
Answer» D. all of the mentioned | |
Explanation: the program will throw an error. |
132. |
1 TEXT FILES, READING AND WRITING FILES, FORMAT OPERATOR |
A. | infile.read(2) |
B. | infile.read() |
C. | infile.readline() |
D. | infile.readlines() |
Answer» A. infile.read(2) | |
Explanation: execute in the shell to verify. |
133. |
print(f.closed) |
A. | true |
B. | false |
C. | none |
D. | error |
Answer» A. true | |
Explanation: the with statement when used with open file guarantees that the file object is closed when the with block exits. |
134. |
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» A. raw_input & input | |
Explanation: python provides two built-in functions to read a line of text from standard input, which by default comes from the keyboard. these functions are: |
135. |
Which one of the following is not attributes of file? |
A. | closed |
B. | softspace |
C. | rename |
D. | mode |
Answer» C. rename | |
Explanation: rename is not the attribute of file rest all are files attributes. |
136. |
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» A. tells you the current position within the file | |
Explanation: the tell() method tells you the current position within the file; in other words, the next read or write will occur at that many bytes from the beginning of the file. |
137. |
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» A. rename(current_file_name, new_file_name) | |
Explanation: this is the correct syntax which has shown below. |
138. |
fo.close() |
A. | compilation error |
B. | syntax error |
C. | displays output |
D. | none of the mentioned |
Answer» C. displays output | |
Explanation: it displays the output as shown below. the method next() is used when a file is used as an iterator, typically in a loop, the next() method is called repeatedly. this method returns the next input line, or raises stopiteration when eof is hit. |
139. |
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» A. sets the file’s current position at the offset | |
Explanation: sets the file’s current position at the offset. the method seek() sets the file’s current position at the offset. |
140. |
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» A. truncates the file size | |
Explanation: the method truncate() truncates the file size. following is the syntax for truncate() method: |
141. |
Which is/are the basic I/O connections in file? |
A. | standard input |
B. | standard output |
C. | standard errors |
D. | all of the mentioned |
Answer» D. all of the mentioned | |
Explanation: standard input, standard output and standard error. standard input is the data that goes to the program. the standard input comes from a keyboard. standard output is where we print our data with the print keyword. unless redirected, it is the terminal console. the standard error is a stream where programs write their error messages. it is usually the text terminal. |
142. |
sys.stdout.write('Python\n') |
A. | compilation error |
B. | runtime error |
C. | hello python |
D. | hello python |
Answer» D. hello python | |
Explanation: none output: |
143. |
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» A. it is used for object serialization | |
Explanation: pickle is the standard mechanism for object serialization. pickle uses a simple stack-based virtual machine that records the instructions used to reconstruct the object. this makes pickle vulnerable to security risks by malformed or maliciously constructed data, that may cause the deserializer to import arbitrary modules and instantiate any object. |
144. |
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» B. it is used for object deserialization | |
Explanation: we have been working with simple textual data. what if we are working with objects rather than simple text? for such situations, we can use the pickle module. this module serializes python objects. the python objects are converted into byte streams and written to text files. this process is called pickling. the inverse operation, reading from a file and reconstructing objects is called deserializing or unpickling. |
145. |
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» B. file object = open(file_name [, access_mode][, buffering]) | |
Explanation: open() function correct syntax with the parameter details as shown below: file object = open(file_name [, access_mode] [, buffering]) |
146. |
fo.close() |
A. | compilation error |
B. | runtime error |
C. | no output |
D. | flushes the file when closing them |
Answer» D. flushes the file when closing them | |
Explanation: the method flush() flushes the internal buffer. python automatically flushes the files when closing them. but you may want to flush the data before closing any file. |
147. |
Correct syntax of file.writelines() is? |
A. | file.writelines(sequence) |
B. | fileobject.writelines() |
C. | fileobject.writelines(sequence) |
D. | none of the mentioned |
Answer» C. fileobject.writelines(sequence) | |
Explanation: the method writelines() writes a sequence of strings to the file. the sequence can be any iterable object producing strings, typically a list of strings. there is no return value. |
148. |
Correct syntax of file.readlines() is? |
A. | fileobject.readlines( sizehint ); |
B. | fileobject.readlines(); |
C. | fileobject.readlines(sequence) |
D. | none of the mentioned |
Answer» A. fileobject.readlines( sizehint ); | |
Explanation: the method readlines() reads until eof using readline() and returns a list containing the lines. if the optional sizehint argument is present, instead of reading up to eof, whole lines totalling approximately sizehint bytes (possibly after rounding up to an internal buffer size) are read. |
149. |
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» A. read, append | |
Explanation: r- reading, a-appending. |
150. |
What is the use of “w” in file handling? |
A. | read |
B. | write |
C. | append |
D. | none of the mentioned |
Answer» B. write | |
Explanation: this opens the file for writing. it will create the file if it doesn’t exist, and if it does, it will overwrite it. |
151. |
What is the use of “a” in file handling? |
A. | read |
B. | write |
C. | append |
D. | none of the mentioned |
Answer» C. append | |
Explanation: this opens the fhe file in appending mode. that means, it will be open for writing and everything will be written to |
152. |
Which function is used to read all the characters? |
A. | read() |
B. | readcharacters() |
C. | readall() |
D. | readchar() |
Answer» A. read() | |
Explanation: the read function reads all characters fh = open(“filename”, “r”) content = fh.read(). |
153. |
Which function is used to read single line from file? |
A. | readline() |
B. | readlines() |
C. | readstatement() |
D. | readfullline() |
Answer» B. readlines() | |
Explanation: the readline function reads a single line from the file fh = open(“filename”, “r”) |
154. |
Which function is used to write all the characters? |
A. | write() |
B. | writecharacters() |
C. | writeall() |
D. | writechar() |
Answer» A. write() | |
Explanation: to write a fixed sequence of characters to a file |
155. |
Which function is used to write a list of string in a file? |
A. | writeline() |
B. | writelines() |
C. | writestatement() |
D. | writefullline() |
Answer» A. writeline() | |
Explanation: with the writeline function you can write a list of strings to a file |
156. |
Which function is used to close a file in python? |
A. | close() |
B. | stop() |
C. | end() |
D. | closefile() |
Answer» A. close() | |
Explanation: f.close()to close it and free up any system resources taken up by the open file. |
157. |
Is it possible to create a text file in python? |
A. | yes |
B. | no |
C. | machine dependent |
D. | all of the mentioned |
Answer» A. yes | |
Explanation: yes we can create a file in python. creation of file is as shown below. file = open(“newfile.txt”, “w”) file.write(“hello world in the new file\n”) file.write(“and another line\n”) file.close(). |
158. |
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» A. wb+ | |
Explanation: here is the description below “w” opens a file for writing only. overwrites the file if the file exists. if the file does not exist, creates a new file for writing. |
159. |
Which of the following is not a valid mode to open a file? |
A. | ab |
B. | rw |
C. | r+ |
D. | w+ |
Answer» B. rw | |
Explanation: use r+, w+ or a+ to perform both read and write operations using a single file object. |
160. |
Which of the following is not a valid attribute of a file object (fp)? |
A. | fp.name |
B. | fp.closed |
C. | fp.mode |
D. | fp.size |
Answer» D. fp.size | |
Explanation: fp.size has not been implemented. |
161. |
How do you close a file object (fp)? |
A. | close(fp) |
B. | fclose(fp) |
C. | fp.close() |
D. | fp. close () |
Answer» C. fp.close() | |
Explanation: close() is a method of the file object. |
162. |
How do you get the current position within the file? |
A. | fp.seek() |
B. | fp.tell() |
C. | fp.loc |
D. | fp.pos |
Answer» B. fp.tell() | |
Explanation: it gives the current position as an offset from the start of file. |
163. |
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» B. os.rename(existing_name, new_name) | |
Explanation: os.rename() is used to rename files. |
164. |
How do you delete a file? |
A. | del(fp) |
B. | fp.delete() |
C. | os.remove(‘file’) |
D. | os.delete(‘file’) |
Answer» C. os.remove(‘file’) | |
Explanation: os.remove() is used to delete files. |
165. |
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» A. fp.seek(offset, 0) | |
Explanation: 0 indicates that the offset is with respect to the start. |
166. |
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» D. error | |
Explanation: seek() takes at least one argument. |
167. |
Which function overloads the == operator? |
A. | eq () |
B. | equ () |
C. | isequal () |
D. | none of the mentioned |
Answer» A. eq () | |
Explanation: the other two do not exist. |
168. |
Which operator is overloaded by lg ()? |
A. | < |
B. | > |
C. | != |
D. | none of the mentioned |
Answer» D. none of the mentioned | |
Explanation: lg () is invalid. |
169. |
Which function overloads the >> operator? |
A. | more () |
B. | gt () |
C. | ge () |
D. | none of the mentioned |
Answer» D. none of the mentioned | |
Explanation: rshift () overloads the >> operator. |
170. |
Let A and B be objects of class Foo. Which functions are called when print(A + B) is executed? |
A. | add (), str () |
B. | str (), add () |
C. | sum (), str () |
D. | str (), sum () |
Answer» A. add (), str () | |
Explanation: the function add () is called first since it is within the bracket. the function str () is then called on the object that we received after adding a and b. |
171. |
Which function overloads the // operator? |
A. | div () |
B. | ceildiv () |
C. | floordiv () |
D. | truediv () |
Answer» C. floordiv () | |
Explanation: floordiv () is for //. |
172. |
How many except statements can a try- except block have? |
A. | zero |
B. | one |
C. | more than one |
D. | more than zero |
Answer» D. more than zero | |
Explanation: there has to be at least one except statement. |
173. |
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» D. always | |
Explanation: the finally block is always executed. |
174. |
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» B. we get a false | |
Explanation: it simply evaluates to false and does not raise any exception. |
175. |
Which of the following is not an exception handling keyword in Python? |
A. | try |
B. | except |
C. | accept |
D. | finally |
Answer» C. accept | |
Explanation: the keywords ‘try’, ‘except’ and ‘finally’ are exception handling keywords in python whereas the word ‘accept’ is not a keyword at all. |
176. |
)) type(g) |
A. | class <’loop’> |
B. | class <‘iteration’> |
C. | class <’range’> |
D. | class <’generator’> |
Answer» D. class <’generator’> | |
Explanation: another way of creating a generator is to use parenthesis. hence the output of the code shown above is: class<’generator’>. |
177. |
+ '3' |
A. | nameerror |
B. | indexerror |
C. | valueerror |
D. | typeerror |
Answer» D. typeerror | |
Explanation: the line of code shown above will result in a type error. this is because the operand ‘+’ is not supported when we combine the data types ‘int’ and ‘str’. sine this is exactly what we have done in the code shown above, a type error is thrown. |
178. |
43') |
A. | importerror |
B. | valueerror |
C. | typeerror |
D. | nameerror |
Answer» B. valueerror | |
Explanation: the snippet of code shown above results in a value error. this is because there is an invalid literal for int() with base 10: ’65.43’. |
179. |
Which of the following statements is true? |
A. | the standard exceptions are automatically imported into python programs |
B. | all raised standard exceptions must be handled in python |
C. | when there is a deviation from the rules of a programming language, a semantic error is thrown |
D. | if any exception is thrown in try block, else block is executed |
Answer» A. the standard exceptions are automatically imported into python programs | |
Explanation: when any exception is thrown in try block, except block is executed. if exception in not thrown in try block, else block is executed. when there is a deviation from the rules of a programming language, a |
180. |
Which of the following is not a standard exception in Python? |
A. | nameerror |
B. | ioerror |
C. | assignmenterror |
D. | valueerror |
Answer» C. assignmenterror | |
Explanation: nameerror, ioerror and valueerror are standard exceptions in python whereas assignment error is not a standard exception in python. |
181. |
Syntax errors are also known as parsing errors. |
A. | true |
B. | false |
Answer» A. true | |
Explanation: syntax errors are known as parsing errors. syntax errors are raised when there is a deviation from the rules of a language. hence the statement is true. |
182. |
An exception is |
A. | an object |
B. | a special function |
C. | a standard module |
D. | a module |
Answer» A. an object | |
Explanation: an exception is an object that is raised by a function signaling that an unexpected situation has occurred, that the function itself cannot handle. |
183. |
exceptions are raised as a result of an error in opening a particular file. |
A. | valueerror |
B. | typeerror |
C. | importerror |
D. | ioerror |
Answer» D. ioerror | |
Explanation: ioerror exceptions are raised as a result of an error in opening or closing a particular file. |
184. |
Which of the following blocks will be executed whether an exception is thrown or not? |
A. | except |
B. | else |
C. | finally |
D. | assert |
Answer» C. finally | |
Explanation: the statements in the finally block will always be executed, whether an exception is thrown or not. this clause is used to close the resources used in a code. |
185. |
Which of these definitions correctly describes a module? |
A. | denoted by triple quotes for providing the specification of certain program elements |
B. | design and implementation of specific functionality to be incorporated into a program |
C. | defines the specification of how it is to be used |
D. | any program that reuses code |
Answer» B. design and implementation of specific functionality to be incorporated into a program | |
Explanation: the term “module” refers to the implementation of specific functionality to be incorporated into a program. |
186. |
Which of the following is not an advantage of using modules? |
A. | provides a means of reuse of program code |
B. | provides a means of dividing up tasks |
C. | provides a means of reducing the size of the program |
D. | provides a means of testing individual parts of the program |
Answer» C. provides a means of reducing the size of the program | |
Explanation: the total size of the program remains the same regardless of whether modules are used or not. modules simply divide the program. |
187. |
Program code making use of a given module is called a of the module. |
A. | client |
B. | docstring |
C. | interface |
D. | modularity |
Answer» A. client | |
Explanation: program code making use of a given module is called the client of the module. there may be multiple clients for a module. |
188. |
is a string literal denoted by triple quotes for providing the specifications of certain program elements. |
A. | interface |
B. | modularity |
C. | client |
D. | docstring |
Answer» D. docstring | |
Explanation: docstring used for providing the specifications of program elements. |
189. |
Which of the following is true about top- down design process? |
A. | the details of a program design are addressed before the overall design |
B. | only the details of the program are addressed |
C. | the overall design of the program is addressed before the details |
D. | only the design of the program is addressed |
Answer» C. the overall design of the program is addressed before the details | |
Explanation: top-down design is an approach for deriving a modular design in which the overall design. |
190. |
In top-down design every module is broken into same number of submodules. |
A. | true |
B. | false |
Answer» B. false | |
Explanation: in top-down design every module can even be broken down into different number of submodules. |
191. |
All modular designs are because of a top- down design process. |
A. | true |
B. | false |
Answer» B. false | |
Explanation: the details of the program can be addressed before the overall design too. |
192. |
Which of the following is not a valid namespace? |
A. | global namespace |
B. | public namespace |
C. | built-in namespace |
D. | local namespace |
Answer» B. public namespace | |
Explanation: during a python program execution, there are as many as three namespaces – built-in namespace, global namespace and local namespace. |
193. |
Which of the following is false about “import modulename” form of import? |
A. | the namespace of imported module becomes part of importing module |
B. | this form of import prevents name clash |
C. | the namespace of imported module becomes available to importing module |
D. | the identifiers in module are accessed as: modulename.identifier |
Answer» A. the namespace of imported module becomes part of importing module | |
Explanation: in the “import modulename” form of import, the namespace of imported module becomes available to, but not part of, the importing module. |
194. |
Which of the following is false about “from-import” form of import? |
A. | the syntax is: from modulename import identifier |
B. | this form of import prevents name clash |
C. | the namespace of imported module becomes part of importing module |
D. | the identifiers in module are accessed directly as: identifier |
Answer» B. this form of import prevents name clash | |
Explanation: in the “from-import” form of import, there may be name clashes because names of the imported identifiers aren’t specified along with the module name. |
195. |
Which of the statements about modules is false? |
A. | in the “from-import” form of import, identifiers beginning with two underscores are private and aren’t imported |
B. | dir() built-in function monitors the items in the namespace of the main module |
C. | in the “from-import” form of import, all identifiers regardless of whether they are private or public are imported |
D. | when a module is loaded, a compiled version of the module with file extension .pyc is automatically produced |
Answer» C. in the “from-import” form of import, all identifiers regardless of whether they are private or public are imported | |
Explanation: in the “from-import” form of import, identifiers beginning with two underscores are private and aren’t imported. |
196. |
What is the order of namespaces in which Python looks for an identifier? |
A. | python first searches the global namespace, then the local namespace and finally the built- in namespace |
B. | python first searches the local namespace, then the global namespace and finally the built-in namespace |
C. | python first searches the built-in namespace, then the global namespace and finally the local namespace |
D. | python first searches the built-in namespace, then the local namespace and finally the global namespace |
Answer» B. python first searches the local namespace, then the global namespace and finally the built-in namespace | |
Explanation: python first searches for the local, then the global and finally the built-in namespace. |
197. |
What type of a structure is this? |
A. | sequence |
B. | case |
C. | repetition |
D. | process |
Answer» B. case | |
Explanation: This is a case structure. Certain cases are given along with a default case in the case structure |
198. |
are identified by their addresses, we give them names (field names / variable names) using words. |
A. | memory variables |
B. | memory locations |
C. | memory addresses |
D. | data variables |
Answer» B. memory locations |
199. |
Operators with the same precedence are evaluated in which manner? |
A. | left to right |
B. | right to left |
C. | can’t say |
D. | none of the mentioned |
Answer» A. left to right |
200. |
The expression Int(x) implies that the variable x is converted to integer. |
A. | true |
B. | false |
Answer» A. true |
Done Reading?