

McqMate
These multiple-choice questions (MCQs) are designed to enhance your knowledge and understanding in the following areas: Computer Science Engineering (CSE) , Information Technology Engineering (IT) , Electrical Engineering , Civil Engineering , Mechanical Engineering .
Chapters
101. |
What will be the output of the following
|
A. | olleh |
B. | hello |
C. | h |
D. | o |
Answer» D. o | |
Explanation: -1 corresponds to the last index. |
102. |
What arithmetic operators cannot be used with strings? |
A. | + |
B. | * |
C. | – |
D. | all of the mentioned |
Answer» C. – | |
Explanation: + is used to concatenate and * is used to multiply strings. |
103. |
What will be the output of the following Python code? >>>print (r"\nhello") |
A. | a new line and hello |
B. | \\nhello |
C. | the letter r and then hello |
D. | error |
Answer» B. \\nhello | |
Explanation: when prefixed with the letter ‘r’ or ‘r’ a string literal becomes a raw string and the escape sequences such as \n are not converted. |
104. |
What will be the output of the following Python code? >>>print('new' 'line') |
A. | error |
B. | output equivalent to print ‘new\\nline’ |
C. | newline |
D. | new line |
Answer» C. newline | |
Explanation: string literal separated by whitespace are allowed. they are concatenated. |
105. |
What will be the output of the following
|
A. | dlrowolleh |
B. | hello |
C. | world |
D. | helloworld |
Answer» A. dlrowolleh | |
Explanation: execute in shell to verify. |
106. |
What will be the output of the following
|
A. | 0xa0xb0xc |
B. | error |
C. | 0x22 |
D. | 33 |
Answer» D. 33 | |
Explanation: 0xa and 0xb and 0xc are hexadecimal integer literals representing the decimal values 10, 11 and 12 respectively. there sum is 33. |
107. |
What will be the output of the following
|
A. | none none |
B. | none 22 |
C. | 22 none |
D. | error is generated |
Answer» D. error is generated | |
Explanation: self.o1 was never created. |
108. |
What will be the output of the following
|
A. | 224 |
B. | error |
C. | 12 |
D. | none |
Answer» C. 12 | |
Explanation: id in this case will be the attribute of the class. |
109. |
3. What will be the output of the following
|
A. | wo |
B. | world |
C. | sn |
D. | rl |
Answer» A. wo | |
Explanation: execute in the shell and verify. |
110. |
What will be the output of the following
|
A. | snow |
B. | snow world |
C. | error |
D. | snos world |
Answer» C. error | |
Explanation: strings cannot be modified. |
111. |
>>>max("what are you") |
A. | error |
B. | u |
C. | t |
D. | y |
Answer» D. y | |
Explanation: max returns the character with the highest ascii value. |
112. |
Given a string example=”hello” what is the output of example.count(‘l’)? |
A. | 2 |
B. | 1 |
C. | none |
D. | 0 |
Answer» A. 2 | |
Explanation: l occurs twice in hello. |
113. |
>>>example.find("e") |
A. | error |
B. | -1 |
C. | 1 |
D. | 0 |
Answer» C. 1 | |
Explanation: returns lowest index. |
114. |
>>>example.rfind("e") |
A. | -1 |
B. | 4 |
C. | 3 |
D. | 1 |
Answer» B. 4 | |
Explanation: returns highest index. |
115. |
>>>example[::-1].startswith("d") |
A. | dlrowolleh |
B. | true |
C. | -1 |
D. | none |
Answer» B. true | |
Explanation: starts with checks if the given string starts with the parameter that is passed. |
116. |
To concatenate two strings to a third what statements are applicable? |
A. | s3 = s1 . s2 |
B. | s3 = s1.add(s2) |
C. | s3 = s1. add (s2) |
D. | s3 = s1 * s2 |
Answer» C. s3 = s1. add (s2) | |
Explanation: add is another method that can be used for concatenation. |
117. |
>>>chr(ord('A')) |
A. | a |
B. | b |
C. | a |
D. | error |
Answer» A. a | |
Explanation: execute in shell to verify. |
118. |
>>>print(chr(ord('b')+1)) |
A. | a |
B. | b |
C. | c |
D. | a |
Answer» C. c | |
Explanation: execute in the shell to verify. |
119. |
Which of the following statement prints hello\example\test.txt? |
A. | print(“hello\\example\\test.txt”) |
B. | print(“hello\\example\\test.txt”) |
C. | print(“hello\\”example\\”test.txt”) |
D. | print(“hello”\\example”\\test.txt”) |
Answer» B. print(“hello\\example\\test.txt”) | |
Explanation: \is used to indicate that the next |
120. |
Suppose s is “\t\tWorld\n”, what is s.strip()? |
A. | \\t\\tworld\\n |
B. | \\t\\tworld\\n |
C. | \\t\\tworld\\n |
D. | world |
Answer» D. world | |
Explanation: execute help(string.strip) to find details. |
121. |
The format function, when applied on a string returns |
A. | error |
B. | int |
C. | bool |
D. | str |
Answer» D. str | |
Explanation: format function returns a string. |
122. |
+2+3? |
A. | hello123 |
B. | hello |
C. | error |
D. | hello6 |
Answer» C. error | |
Explanation: cannot concatenate str and int objects. |
123. |
>>>print("A", end = ' ') |
A. | dcba |
B. | a, b, c, d |
C. | d c b a |
D. | d, c, b, a will be displayed on four lines |
Answer» C. d c b a | |
Explanation: execute in the shell. |
124. |
What will be displayed by print(ord(‘b’) – ord(‘a’))? |
A. | 0 |
B. | 1 |
C. | -1 |
D. | 2 |
Answer» B. 1 | |
Explanation: ascii value of b is one more than a. hence the output of this code is 98-97, which is equal to 1. |
125. |
Say s=”hello” what will be the return value of type(s)? |
A. | int |
B. | bool |
C. | str |
D. | string |
Answer» C. str | |
Explanation: str is used to represent strings in python. |
126. |
What is “Hello”.replace(“l”, “e”)? |
A. | heeeo |
B. | heelo |
C. | heleo |
D. | none |
Answer» A. heeeo | |
Explanation: execute in shell to verify. |
127. |
To retrieve the character at index 3 from string s=”Hello” what command do we execute (multiple answers allowed)? |
A. | s[] |
B. | s.getitem(3) |
C. | s. getitem (3) |
D. | s.getitem(3) |
Answer» C. s. getitem (3) | |
Explanation: getitem(..) can be used to get character at index specified as parameter. |
128. |
To return the length of string s what command do we execute? |
A. | s. len () |
B. | len(s) |
C. | size(s) |
D. | s.size() |
Answer» A. s. len () | |
Explanation: execute in shell to verify. |
129. |
If a class defines the str (self) method, for an object obj for the class, you can use which command to invoke the str method. |
A. | obj. str () |
B. | str(obj) |
C. | print obj |
D. | all of the mentioned |
Answer» D. all of the mentioned | |
Explanation: execute in shell to verify. |
130. |
To check whether string s1 contains another string s2, use |
A. | s1. contains (s2) |
B. | s2 in s1 |
C. | s1.contains(s2) |
D. | si.in(s2) |
Answer» A. s1. contains (s2) | |
Explanation: s2 in s1 works in the same way as calling the special function contains . |
131. |
Suppose i is 5 and j is 4, i + j is same as |
A. | i. add(j) |
B. | i. add (j) |
C. | i. add(j) |
D. | i. add(j) |
Answer» B. i. add (j) | |
Explanation: execute in shell to verify. |
132. |
What function do you use to read a string? |
A. | input(“enter a string”) |
B. | eval(input(“enter a string”)) |
C. | enter(“enter a string”) |
D. | eval(enter(“enter a string”)) |
Answer» A. input(“enter a string”) | |
Explanation: execute in shell to verify. |
133. |
What is the default value of encoding in encode()? |
A. | ascii |
B. | qwerty |
C. | utf-8 |
D. | utf-16 |
Answer» C. utf-8 | |
Explanation: the default value of encoding is utf-8. |
134. |
Which of the following functions is a built- in function in python? |
A. | seed() |
B. | sqrt() |
C. | factorial() |
D. | print() |
Answer» D. print() | |
Explanation: the function seed is a function which is present in the random module. the functions sqrt and factorial are a part of the math module. the print function is a built-in function which prints a value directly to the system output. |
135. |
What is the output of the function complex()? |
A. | 0j |
B. | 0+0j |
C. | 0 |
D. | error |
Answer» A. 0j | |
Explanation: the complex function returns 0j if both of the arguments are omitted, that is, if the function is in the form of complex() or complex(0), then the output will be 0j. |
136. |
The function divmod(a,b), where both ‘a’ and ‘b’ are integers is evaluated as: |
A. | (a%b, a//b) |
B. | (a//b, a%b) |
C. | (a//b, a*b) |
D. | (a/b, a%b) |
Answer» B. (a//b, a%b) | |
Explanation: the function divmod(a,b) is evaluated as a//b, a%b, if both ‘a’ and ‘b’ are integers. |
137. |
The function complex(‘2-3j’) is valid but the function complex(‘2 – 3j’) is invalid. |
A. | true |
B. | false |
Answer» A. true | |
Explanation: when converting from a string, the string must not contain any blank spaces around the + or – operator. hence the function complex(‘2 – 3j’) will result in an error. |
138. |
Which of the following functions does not necessarily accept only iterables as arguments? |
A. | enumerate() |
B. | all() |
C. | chr() |
D. | max() |
Answer» C. chr() | |
Explanation: the functions enumerate(), all() and max() accept iterables as arguments whereas the function chr() throws an error on receiving an iterable as an argument. also note that the function chr() accepts only integer values. |
139. |
Which of the following functions accepts only integers as arguments? |
A. | ord() |
B. | min() |
C. | chr() |
D. | any() |
Answer» C. chr() | |
Explanation: the function chr() accepts only integers as arguments. the function ord() accepts only strings. the functions min() and max() can accept floating point as well as integer arguments. |
140. |
Suppose there is a list such that: l=[2,3,4]. If we want to print this list in reverse order, which of the following methods should be used? |
A. | reverse(l) |
B. | list(reverse[(l)]) |
C. | reversed(l) |
D. | list(reversed(l)) |
Answer» D. list(reversed(l)) | |
Explanation: the built-in function reversed() can be used to reverse the elements of a list. this function accepts only an iterable as an argument. to print the output in the form of a list, we use: list(reversed(l)). the output will be: [4,3,2]. |
141. |
Which of the following functions will not result in an error when no arguments are passed to it? |
A. | min() |
B. | divmod() |
C. | all() |
D. | float() |
Answer» D. float() | |
Explanation: the built-in functions min(), max(), divmod(), ord(), any(), all() etc throw an error when no arguments are passed to them. however there are some built-in functions like float(), complex() etc which do not throw an error when no arguments are passed to them. the output of float() is 0.0. |
142. |
Which of the following functions does not throw an error? |
A. | ord() |
B. | ord(‘ ‘) |
C. | ord(”) |
D. | ord(“”) |
Answer» B. ord(‘ ‘) | |
Explanation: the function ord() accepts a character. hence ord(), ord(”) and ord(“”) |
143. |
Which of the following is the use of function in python? |
A. | functions are reusable pieces of programs |
B. | functions don’t provide better modularity for your application |
C. | you can’t also create your own functions |
D. | all of the mentioned |
Answer» A. functions are reusable pieces of programs | |
Explanation: functions are reusable pieces of programs. they allow you to give a name to a block of statements, allowing you to run that block using the specified name anywhere in your program and any number of times. |
144. |
printMax(3, 4) |
A. | 3 |
B. | 4 |
C. | 4 is maximum |
D. | none of the mentioned |
Answer» C. 4 is maximum | |
Explanation: here, we define a function called printmax that uses two parameters called a and b. we find out the greater number using a simple if..else statement and then print the bigger number. |
145. |
print(maximum(2, 3)) |
A. | 2 |
B. | 3 |
C. | the numbers are equal |
D. | none of the mentioned |
Answer» B. 3 | |
Explanation: the maximum function returns the maximum of the parameters, in this case the numbers supplied to the function. it uses a simple if..else statement to find the greater value and then returns that value. |
146. |
Which of the following is a feature of DocString? |
A. | provide a convenient way of associating documentation with python modules, functions, classes, and methods |
B. | all functions should have a docstring |
C. | docstrings can be accessed by the doc attribute on objects |
D. | all of the mentioned |
Answer» D. all of the mentioned | |
Explanation: python has a nifty feature called documentation strings, usually referred to by its shorter name docstrings. docstrings |
147. |
What are the two main types of functions? |
A. | custom function |
B. | built-in function & user defined function |
C. | user function |
D. | system function |
Answer» B. built-in function & user defined function | |
Explanation: built-in functions and user defined ones. the built-in functions are part of the python language. examples are: dir(), len() or abs(). the user defined functions are functions created with the def keyword. |
148. |
Where is function defined? |
A. | module |
B. | class |
C. | another function |
D. | all of the mentioned |
Answer» D. all of the mentioned | |
Explanation: functions can be defined inside a module, a class or another function. |
149. |
Which of the following is the use of id() function in python? |
A. | id returns the identity of the object |
B. | every object doesn’t have a unique id |
C. | all of the mentioned |
D. | none of the mentioned |
Answer» A. id returns the identity of the object | |
Explanation: each object in python has a unique id. the id() function returns the object’s id. |
150. |
Which of the following refers to mathematical function? |
A. | sqrt |
B. | rhombus |
C. | add |
D. | rhombus |
Answer» A. sqrt | |
Explanation: functions that are always available for usage, functions that are contained within external modules, which must be imported and functions defined by a programmer with the def keyword. |
Done Studing? Take A Test.
Great job completing your study session! Now it's time to put your knowledge to the test. Challenge yourself, see how much you've learned, and identify areas for improvement. Don’t worry, this is all part of the journey to mastery. Ready for the next step? Take a quiz to solidify what you've just studied.