

InterviewSolution
Saved Bookmarks
This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.
151. |
What is returned by math.ceil(3.4)?(a) 3(b) 4(c) 4.0(d) 3.0 |
Answer» The correct choice is (b) 4 The explanation: The ceil function returns the smallest integer that is bigger than or equal to the number itself. |
|
152. |
What is the result of round(0.5) – round(-0.5)?(a) 1.0(b) 2.0(c) 0.0(d) Value depends on Python version |
Answer» Right choice is (d) Value depends on Python version Easiest explanation - The behavior of the round() function is different in Python 2 and Python 3. In Python 2, it rounds off numbers away from 0 when the number to be rounded off is exactly halfway through. round(0.5) is 1 and round(-0.5) is -1 whereas in Python 3, it rounds off numbers towards nearest even number when the number to be rounded off is exactly halfway through. See the below output. |
|
153. |
What is the result of cmp(3, 1)?(a) 1(b) 0(c) True(d) False |
Answer» Correct option is (a) 1 Best explanation: cmp(x, y) returns 1 if x > y, 0 if x == y and -1 if x < y. |
|
154. |
What is the result of math.fsum([.1 for i in range(20)])?(a) 2.0(b) 20(c) 2(d) 2.0000000000000004 |
Answer» Right answer is (a) 2.0 Easy explanation - The function fsum returns an accurate floating point sum of the elements of its argument. |
|
155. |
What does ~~~~~~5 evaluate to?(a) +5(b) -11(c) +11(d) -5 |
Answer» The correct answer is (a) +5 Easiest explanation - ~x is equivalent to -(x+1). ~~x = – (-(x+1) + 1) = (x+1) – 1 = x ~~x is equivalent to x Extrapolating further ~~~~~~x would be same as x in the final result. In the question, x value is given as 5 and “~” is repeated 6 times. So, the correct answer for “~~~~~~5” is 5. |
|
156. |
What does 3 ^ 4 evaluate to?(a) 81(b) 12(c) 0.75(d) 7 |
Answer» Correct option is (d) 7 For explanation: ^ is the Binary XOR operator. |
|
157. |
What does ~4 evaluate to?(a) -5(b) -4(c) -3(d) +3 |
Answer» The correct option is (a) -5 Best explanation: ~x is equivalent to -(x+1). |
|
158. |
What is x if x = math.isfinite(float(‘0.0’))?(a) True(b) False(c) None(d) error |
Answer» Right answer is (a) True To explain I would say: float(‘0.0’) is a finite number. |
|
159. |
What is the result of sum([.1 for i in range(20)])?(a) 2.0(b) 20(c) 2(d) 2.0000000000000004 |
Answer» Right answer is (d) 2.0000000000000004 Explanation: There is some loss of accuracy when we use sum with floating point numbers. Hence the function fsum is preferable. |
|
160. |
What is the value of x if x = math.ldexp(0.5, 1)?(a) 1(b) 2.0(c) 0.5(d) none of the mentioned |
Answer» Correct choice is (d) none of the mentioned Best explanation: The value returned by ldexp(x, y) is x * (2 ** y). In the current case x is 1.0. |
|
161. |
What is returned by math.modf(1.0)?(a) (0.0, 1.0)(b) (1.0, 0.0)(c) (0.5, 1)(d) (0.5, 1.0) |
Answer» Right answer is (a) (0.0, 1.0) To explain: The first element is the fractional part and the second element is the integral part of the argument. |
|
162. |
What is returned by math.isfinite(float(‘inf’))?(a) True(b) False(c) None(d) error |
Answer» The correct answer is (b) False Easy explanation - float(‘inf’) is not a finite number. |
|
163. |
What is returned by math.isfinite(float(‘nan’))?(a) True(b) False(c) None(d) error |
Answer» Right answer is (b) False Easy explanation - float(‘nan’) is not a finite number. |
|
164. |
What is the two’s complement of -44?(a) 1011011(b) 11010100(c) 11101011(d) 10110011 |
Answer» Correct option is (b) 11010100 Best explanation: The binary form of -44 is 00101100. The one’s complement of this value is 11010011. On adding one to this we get: 11010100 (two’s complement). |
|
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» Right answer is (a) fp.seek(offset, 0) Explanation: 0 indicates that the offset is with respect to the start. |
|
166. |
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» The correct answer is (b) os.rename(existing_name, new_name) Best explanation: os.rename() is used to rename files. |
|
167. |
How do you delete a file?(a) del(fp)(b) fp.delete()(c) os.remove(‘file’)(d) os.delete(‘file’) |
Answer» Right choice is (c) os.remove(‘file’) Explanation: os.remove() is used to delete files. |
|
168. |
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» Right choice is (a) Returns True if any key of the dictionary is true The explanation is: Method any() returns True if any key of the dictionary is true and False if the dictionary is empty. |
|
169. |
What does os.fchmod(fd, mode) do?(a) change permission bits of the file(b) change permission bits of the directory(c) change permission bits of either the file or the directory(d) none of the mentioned |
Answer» Correct option is (a) change permission bits of the file The best explanation: The arguments to the function are a file descriptor and the new mode. |
|
170. |
What does os.name contain?(a) the name of the operating system dependent module imported(b) the address of the module os(c) error, it should’ve been os.name()(d) none of the mentioned |
Answer» Correct answer is (a) the name of the operating system dependent module imported Explanation: It contains the name of the operating system dependent module imported such as ‘posix’, ‘java’ etc. |
|
171. |
What does os.close(f) do?(a) terminate the process f(b) terminate the process f if f is not responding(c) close the file descriptor f(d) return an integer telling how close the file pointer is to the end of file |
Answer» The correct option is (c) close the file descriptor f Easiest explanation - When a file descriptor is passed as an argument to os.close() it will be closed. |
|
172. |
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» Right answer is (d) All of the mentioned Explanation: Dictionaries are created by specifying keys and values. |
|
173. |
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» Right choice is (c) del d[“john”] Easy explanation - Execute in the shell to verify. |
|
174. |
The function of re.search is __________(a) Matches a pattern at the start of the string(b) Matches a pattern at the end of the string(c) Matches a pattern from any part of a string(d) Such a function does not exist |
Answer» The correct option is (c) Matches a pattern from any part of a string The best I can explain: The re module of Python consists of a function re.search. It’s function is to match a pattern from anywhere in a string. |
|
175. |
The process of pickling in Python includes:(a) conversion of a list into a datatable(b) conversion of a byte stream into Python object hierarchy(c) conversion of a Python object hierarchy into byte stream(d) conversion of a datatable into a list |
Answer» Right choice is (c) conversion of a Python object hierarchy into byte stream Easy explanation - Pickling is the process of sterilizing a Python object, that is, conversion of a byte stream into Python object hierarchy. The reverse of this process is known as unpickling. |
|
176. |
What does os.link() do?(a) create a symbolic link(b) create a hard link(c) create a soft link(d) none of the mentioned |
Answer» The correct answer is (b) create a hard link The best I can explain: os.link(source, destination) will create a hard link from source to destination. |
|
177. |
Which of the following functions results in an error?(a) turtle.shape(“turtle”)(b) turtle.shape(“square”)(c) turtle.shape(“triangle”)(d) turtle.shape(“rectangle”) |
Answer» The correct choice is (d) turtle.shape(“rectangle”) Easy explanation - The functions shown above will change the arrow to the shape mentioned. The functions turtle.shape(“turtle”), turtle.shape(“square”) and turtle.shape(“triangle”) are valid whereas the function turtle.shape(“rectangle”) is invalid. |
|
178. |
To include the use of functions which are present in the random library, we must use the option:(a) import random(b) random.h(c) import.random(d) random.random |
Answer» Correct option is (a) import random The best I can explain: The command import random is used to import the random module, which enables us to use the functions which are present in the random library. |
|
179. |
Which of the following can be used to create a directory?(a) os.mkdir()(b) os.creat_dir()(c) os.create_dir()(d) os.make_dir() |
Answer» Right choice is (a) os.mkdir() Explanation: The function mkdir() creates a directory in the path specified. |
|
180. |
Which of the following functions results in case insensitive matching?(a) re.A(b) re.U(c) re.I(d) re.X |
Answer» The correct answer is (c) re.I Explanation: The function re.I (that is, re.IGNORECASE) results in case-insensitive matching. That is, expressions such as [A-Z] will match lowercase characters too. |
|
181. |
What is the answer to this expression, 22 % 3 is?(a) 7(b) 1(c) 0(d) 5 |
Answer» Correct answer is (b) 1 Explanation: Modulus operator gives the remainder. So, 22%3 gives the remainder, that is, 1. |
|
182. |
Which of the following functions helps us to randomize the items of a list?(a) seed(b) randomise(c) shuffle(d) uniform |
Answer» The correct choice is (c) shuffle The best I can explain: The function shuffle, which is included in the random module, helps us to randomize the items of a list. This function takes the list as a parameter. |
|
183. |
Which is the most appropriate definition for recursion?(a) A function that calls itself(b) A function execution instance that calls another execution instance of the same function(c) A class method that calls another class method(d) An in-built method that is automatically called |
Answer» Right answer is (b) A function execution instance that calls another execution instance of the same function The explanation is: The appropriate definition for a recursive function is a function execution instance that calls another execution instance of the same function either directly or indirectly. |
|
184. |
The function used to alter the thickness of the pen to ‘x’ units:(a) turtle.width(x)(b) turtle.span(x)(c) turtle.girth(x)(d) turtle.thickness(x) |
Answer» Right choice is (a) turtle.width(x) Explanation: The function turtle.width(x) is used to alter the thickness of the pen to ‘x’ units. The function turtle.span(x), turtle.girth(x) and turtle.thickness(x) are invalid. |
|
185. |
Which of the following can be used to create a symbolic link?(a) os.symlink()(b) os.symb_link()(c) os.symblin()(d) os.ln() |
Answer» Correct answer is (a) os.symlink() For explanation: It is the function that allows you to create a symbolic link. |
|
186. |
Where are the arguments received from the command line stored?(a) sys.argv(b) os.argv(c) argv(d) none of the mentioned |
Answer» Correct choice is (a) sys.argv Easy explanation - Refer documentation. |
|
187. |
In which direction is the turtle pointed by default?(a) North(b) South(c) East(d) West |
Answer» Right option is (c) East For explanation: By default, the turtle is pointed towards the east direction. We can change the direction of the turtle by using certain commands. However, whenever the turtle is reset, it points towards east. |
|
188. |
The command which helps us to reset the pen (turtle):(a) turtle.reset(b) turtle.penreset(c) turtle.penreset()(d) turtle.reset() |
Answer» Correct choice is (d) turtle.reset() Best explanation: The command turtle.reset() helps us to reset the pen. After the execution of this command, we get a blank page with an arrow on it. We can then perform any desired operation on this page. |
|
189. |
Which one of these is floor division?(a) /(b) //(c) %(d) None of the mentioned |
Answer» Correct option is (b) // The best I can explain: When both of the operands are integer then python chops out the fraction part and gives you the round off value, to get the accurate answer use floor division. This is floor division. For ex, 5/2 = 2.5 but both of the operands are integer so answer of this expression in python is 2. To get the 2.5 answer, use floor division. |
|
190. |
Which of the following functions can be used to make the arrow black?(a) turtle.color(0,1,0)(b) turtle.color(1,0,0)(c) turtle.color(0,0,1)(d) turtle.color(0,0,0) |
Answer» Right choice is (d) turtle.color(0,0,0) Explanation: The function turtle.color(0,0,0) can change the colour of the arrow. The function turtle.color(0,1,0) will make the arrow green. The function turtle.color(1,0,0) will make the arrow red. The function turtle.color(0,0,1) will make the arrow blue. The function turtle.color(0,0,0) will make the arrow black. |
|
191. |
How many keyword arguments can be passed to a function in a single function call?(a) zero(b) one(c) zero or more(d) one or more |
Answer» Correct option is (c) zero or more Explanation: Zero keyword arguments may be passed if all the arguments have default values. |
|
192. |
How are default arguments specified in the function heading?(a) identifier followed by an equal to sign and the default value(b) identifier followed by the default value within backticks (“)(c) identifier followed by the default value within square brackets ([])(d) identifier |
Answer» Right choice is (a) identifier followed by an equal to sign and the default value The explanation is: Refer documentation. |
|
193. |
All keywords in Python are in _________(a) lower case(b) UPPER CASE(c) Capitalized(d) None of the mentioned |
Answer» Right answer is (d) None of the mentioned The best explanation: True, False and None are capitalized while the others are in lower case. |
|
194. |
Which is the correct operator for power(x^y)?(a) X^y(b) X**y(c) X^^y(d) None of the mentioned |
Answer» Right choice is (b) X**y To explain I would say: In python, power operator is x**y i.e. 2**3=8. |
|
195. |
Which of the following functions does not accept any arguments?(a) position(b) fillcolor(c) goto(d) setheading() |
Answer» Correct option is (a) position Best explanation: The functions fillcolor(), goto() and setheading() accept arguments, whereas the function position() does not accept any arguments. The function position() returns the current position of the turtle. |
|
196. |
Which of the following is true for variable names in Python?(a) unlimited length(b) all private members must have leading and trailing underscores(c) underscore and ampersand are the only two special characters allowed(d) none of the mentioned |
Answer» Right choice is (a) unlimited length To explain I would say: Variable names can be of any length. |
|
197. |
How are variable length arguments specified in the function heading?(a) one star followed by a valid identifier(b) one underscore followed by a valid identifier(c) two stars followed by a valid identifier(d) two underscores followed by a valid identifier |
Answer» Correct option is (a) one star followed by a valid identifier The best I can explain: Refer documentation. |
|
198. |
Which of the following cannot be a variable?(a) __init__(b) in(c) it(d) on |
Answer» Right choice is (b) in The best I can explain: in is a keyword. |
|
199. |
Which of the following commands will create a list?(a) list1 = list()(b) list1 = [](c) list1 = list([1, 2, 3])(d) all of the mentioned |
Answer» Right choice is (d) all of the mentioned Easy explanation - Execute in the shell to verify |
|
200. |
What is the default value of encoding in encode()?(a) ascii(b) qwerty(c) utf-8(d) utf-16 |
Answer» Correct option is (c) utf-8 The best explanation: The default value of encoding is utf-8. |
|