Python MCQ Answer Sheet 2
Python MCQ Answer Sheet 2
1. Answer: c
Explanation: Python language is designed by a Dutch programmer Guido van Rossum
in the Netherlands.
2. Answer: d
Explanation: Python is an interpreted programming language, which supports object-
oriented, structured, and functional programming
3. Answer: b
Explanation: Case is always significant while dealing with identifiers in python.
4. Answer: c
Explanation: ‘.py’ is the correct extension of the Python file. Python programs can be
written in any text editor. To save these programs we need to save in files with file
extension ‘.py’.
5. Answer: a
Explanation: Many languages have been implemented using both compilers and
interpreters, including C, Pascal, and Python
6. Answer: d
Explanation: True, False and None are capitalized while the others are in lower case.
7. Answer: a
Explanation: The order of precedence is: %, +. Hence the expression above, on
simplification results in 4 + 3 = 7. Hence the result is 7.
8. Answer: a
Explanation: In Python, to define a block of code we use indentation. Indentation refers
to whitespaces at the beginning of the line.
9. Answer: b
Explanation: The def keyword is used to create, (or define) a function in python.
10. Answer: b
Explanation: To write single-line comments in Python use the Hash character (#) at the
beginning of the line. It is also called number sign or pound sign. To write multi-line
comments, close the text between triple quotes.
Example: “”” comment
text “””
11. Answer: b
Explanation: SyntaxError, there shouldn’t be a space between + and = in +=.
12. Answer: d
Explanation: The function sys.version can help us to find the version of python that we
are currently working on. It also contains information on the build number and compiler
used. For example, 3.5.2, 2.7.3 etc. this function also returns the current date, time, bits
etc along with the version.
13. Answer: c
Explanation: Python supports the creation of anonymous functions (i.e. functions that
are not bound to a name) at runtime, using a construct called lambda. Lambda functions
are restricted to a single expression. They can be used wherever normal functions can
be used.
14. Answer: d
Explanation: For order of precedence, just remember this PEMDAS (similar to
BODMAS).
15. Answer: a
Explanation: The binary form of 1 is 0001. The expression x<<2 implies we are
performing bitwise left shift on x. This shift yields the value: 0100, which is the binary
form of the number 4.
16. Answer: c
Explanation: pip is a package manager for python. Which is also called Preferred
Installer Program.
17. Answer: b
Explanation: Variable names can be of any length.
18. Answer: a
Explanation: Expression 1 is evaluated as: 2**9, which is equal to 512. Expression 2 is
evaluated as 8**2, which is equal to 64. The last expression is evaluated as 2**(3**2).
This is because the associativity of ** operator is from right to left. Hence the result of
the third expression is 512.
19. Answer: b
Explanation: // is the operator for truncation division. It is called so because it returns
only the integer part of the quotient, truncating the decimal part. For example: 20//3 = 6.
20. Answer: c
Explanation: The code shown above returns a new list containing only those elements of
the list l which do not amount to zero. Hence the output is: [1, 2, ‘hello’].
21. Answer: b
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.
22. Answer: b
Explanation: Each object in Python has a unique id. The id() function returns the object’s
id.
23. Answer: a
Explanation: The code shown above shows a general decorator which can work with
any number of arguments.
24. Answer: d
Explanation: The function max() is being used to find the maximum value from among -
3, -4 and false. Since false amounts to the value zero, hence we are left with min(0, 2, 7)
Hence the output is 0 (false).
25. Answer: c
Explanation: Class is a user-defined data type.
26. Answer: d
Explanation: The expression shown above rounds off the given number to the number of
decimal places specified. Since the expression given specifies rounding off to two
decimal places, the output of this expression will be 56.24. Had the value been x=56.234
(last digit being any number less than 5), the output would have been 56.23.
27. Answer: b
Explanation: A folder of python programs is called as a package of modules.
28. Answer: c
Explanation: The function len() returns the length of the number of elements in the
iterable. Therefore the output of the function shown above is 4.
29. Answer: c
Explanation: Python first searches for the local, then the global and finally the built-in
namespace.
30. Answer: c
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.
31.Answer: a
Explanation: [::-1] reverses the list.
32. Answer: b
Explanation: + operator is concatenation operator.
33. Answer: c
Explanation: Both str(f) and format(f) call f.__str__().
34. Answer: b
Explanation: eval can be used as a variable.
35. Answer: a
Explanation: Id in this case will be the attribute of the instance.
36. Answer: d
Explanation: The same object is modified in the function.
37.Answer: b
Explanation: getopt parses options received from the command line.
38. Answer: c
Explanation: The code shown first adds the element ‘san’ to the set z. The set z is then
updated and two more elements, namely, ‘p’ and ‘q’ are added to it. Hence the output is:
{‘a’, ‘b’, ‘c’, ‘p’, ‘q’, ‘san’}
39. Answer: b
Explanation: + is used to concatenate and * is used to multiply strings.
40. Answer: a
Explanation: The first letter of the string is converted to uppercase and the others are
converted to lowercase.
41. Answer: d
Explanation: { } creates a dictionary not a set. Only set() creates an empty set.
42. Answer: a
Explanation: Here, ‘result’ is a list which is extending three times. When first time
‘extend’ function is called for ‘result’, the inner code generates a generator object, which
is further used in ‘extend’ function. This generator object contains the values which are
in ‘list1’ only (not in ‘list2’ and ‘list3’).
Same is happening in second and third call of ‘extend’ function in these generator object
contains values only in ‘list2’ and ‘list3’ respectively.
So, ‘result’ variable will contain elements which are only in one list (not more than 1 list).
43. Answer: c
Explanation: We use the function append to add an element to the list.
44. Answer: b
Explanation: Padding is done towards the right-hand-side first when the final string is of
even length.
45. Answer: c
Explanation: Lists should be copied by executing [:] operation.
46. Answer: c
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.
47. Answer: b
Explanation: The output that is required is 6, that is, row 2, item 3. This position is
represented by the statement: A[1][2].
48. Answer: d
Explanation: Identifiers can be of any length.
49. Answer: c
Explanation: The else part is not executed if control breaks out of the loop.
50. Answer: d
Explanation: i takes values 0, 1, 2 and 3.