

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
51. |
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(“”) |
52. |
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. |
53. |
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. |
54. |
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. |
55. |
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 |
56. |
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. |
57. |
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. |
58. |
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. |
59. |
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. |
60. |
print x |
A. | 9 |
B. | 3 |
C. | 27 |
D. | 30 |
Answer» C. 27 | |
Explanation: a function is created to do a specific task. often there is a result from such a task. the return keyword is used to return |
61. |
Python supports the creation of anonymous functions at runtime, using a construct called |
A. | lambda |
B. | pi |
C. | anonymous |
D. | none of the mentioned |
Answer» A. lambda | |
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. |
62. |
print z(8) |
A. | 48 |
B. | 14 |
C. | 64 |
D. | none of the mentioned |
Answer» A. 48 | |
Explanation: the lambda keyword creates an anonymous function. the x is a parameter, that is passed to the lambda function. the parameter is followed by a colon character. |
63. |
Does Lambda contains return statements? |
A. | true |
B. | false |
Answer» B. false | |
Explanation: lambda definition does not include a return statement. it always contains an expression which is returned. also note that we can put a lambda definition anywhere a function is expected. we don’t have to assign it to a variable at all. |
64. |
Lambda is a statement. |
A. | true |
B. | false |
Answer» B. false | |
Explanation: lambda is an anonymous function in python. hence this statement is false. |
65. |
What is a variable defined outside a function referred to as? |
A. | a static variable |
B. | a global variable |
C. | a local variable |
D. | an automatic variable |
Answer» B. a global variable | |
Explanation: the value of a variable defined outside all function definitions is referred to as a global variable and can be used by multiple functions of the program. |
66. |
What is a variable defined inside a function referred to as? |
A. | a global variable |
B. | a volatile variable |
C. | a local variable |
D. | an automatic variable |
Answer» C. a local variable | |
Explanation: the variable inside a function is called as local variable and the variable definition is confined only to that function. |
67. |
If a function doesn’t have a return statement, which of the following does the function return? |
A. | int |
B. | null |
C. | none |
D. | an exception is thrown without the return statement |
Answer» C. none | |
Explanation: a function can exist without a return statement and returns none if the function doesn’t have a return statement. |
68. |
What is the type of each element in sys.argv? |
A. | set |
B. | list |
C. | tuple |
D. | string |
Answer» D. string | |
Explanation: it is a list of strings. |
69. |
What is the length of sys.argv? |
A. | number of arguments |
B. | number of arguments + 1 |
C. | number of arguments – 1 |
D. | none of the mentioned |
Answer» B. number of arguments + 1 | |
Explanation: the first argument is the name of the program itself. therefore the length of sys.argv is one more than the number arguments. |
70. |
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» C. zero or more | |
Explanation: zero keyword arguments may be passed if all the arguments have default values. |
71. |
Which module in the python standard library parses options received from the command line? |
A. | getopt |
B. | os |
C. | getarg |
D. | main |
Answer» A. getopt | |
Explanation: getopt parses options received from the command line. |
72. |
What is the type of sys.argv? |
A. | set |
B. | list |
C. | tuple |
D. | string |
Answer» B. list | |
Explanation: it is a list of elements. |
73. |
Which of the following data structures is returned by the functions globals() and locals()? |
A. | list |
B. | set |
C. | dictionary |
D. | tuple |
Answer» C. dictionary | |
Explanation: both the functions, that is, globals() and locals() return value of the data structure dictionary. |
74. |
On assigning a value to a variable inside a function, it automatically becomes a global variable. |
A. | true |
B. | false |
Answer» B. false | |
Explanation: on assigning a value to a variable inside a function, t automatically becomes a local variable. hence the above statement is false. |
75. |
What happens if a local variable exists with the same name as the global variable you want to access? |
A. | error |
B. | the local variable is shadowed |
C. | undefined behavior |
D. | the global variable is shadowed |
Answer» D. the global variable is shadowed | |
Explanation: if a local variable exists with the same name as the local variable that you want to access, then the global variable is shadowed. that is, preference is given to the local variable. |
76. |
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» B. a function execution instance that calls another execution instance of the same function | |
Explanation: 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. |
77. |
Only problems that are recursively defined can be solved using recursion. |
A. | true |
B. | false |
Answer» B. false | |
Explanation: there are many other problems can also be solved using recursion. |
78. |
Which of these is false about recursion? |
A. | recursive function can be replaced by a non-recursive function |
B. | recursive functions usually take more memory space than non-recursive function |
C. | recursive functions run faster than non- recursive function |
D. | recursion makes programs easier to understand |
Answer» C. recursive functions run faster than non- recursive function | |
Explanation: the speed of a program using recursion is slower than the speed of its non- recursive equivalent. |
79. |
What is tail recursion? |
A. | a recursive function that has two base cases |
B. | a function where the recursive functions leads to an infinite loop |
C. | a recursive function where the function doesn’t return anything and just prints the values |
D. | a function where the recursive call is the last thing executed by the function |
Answer» D. a function where the recursive call is the last thing executed by the function | |
Explanation: a recursive function is tail recursive when recursive call is executed by the function in the last. |
80. |
Which of the following statements is false about recursion? |
A. | every recursive function must have a base case |
B. | infinite recursion can occur if the base case isn’t properly mentioned |
C. | a recursive function makes the code easier to understand |
D. | every recursive function must have a return value |
Answer» D. every recursive function must have a return value | |
Explanation: a recursive function needn’t have a return value. |
81. |
Recursion and iteration are the same programming approach. |
A. | true |
B. | false |
Answer» B. false | |
Explanation: in recursion, the function calls itself till the base condition is reached whereas iteration means repetition of process for example in for-loops. |
82. |
What happens if the base condition isn’t defined in recursive programs? |
A. | program gets into an infinite loop |
B. | program runs once |
C. | program runs n number of times where n is the argument given to the function |
D. | an exception is thrown |
Answer» A. program gets into an infinite loop | |
Explanation: the program will run until the system gets out of memory. |
83. |
Which of these is not true about recursion? |
A. | making the code look clean |
B. | a complex task can be broken into sub- problems |
C. | recursive calls take up less memory |
D. | sequence generation is easier than a nested iteration |
Answer» C. recursive calls take up less memory | |
Explanation: recursive calls take up a lot of memory and time as memory is taken up each time the function is called. |
84. |
Which of these is not true about recursion? |
A. | it’s easier to code some real-world problems using recursion than non-recursive equivalent |
B. | recursive functions are easy to debug |
C. | recursive calls take up a lot of memory |
D. | programs using recursion take longer time than their non-recursive equivalent |
Answer» B. recursive functions are easy to debug | |
Explanation: recursive functions may be hard to debug as the logic behind recursion may be hard to follow. |
85. |
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» D. all of the mentioned | |
Explanation: execute in the shell to verify |
86. |
What is the output when we execute list(“hello”)? |
A. | [‘h’, ‘e’, ‘l’, ‘l’, ‘o’] |
B. | [‘hello’] |
C. | [‘llo’] |
D. | [‘olleh’] |
Answer» A. [‘h’, ‘e’, ‘l’, ‘l’, ‘o’] | |
Explanation: execute in the shell to verify. |
87. |
Suppose list1 is [2445,133,12454,123], what is max(list1)? |
A. | 2445 |
B. | 133 |
C. | 12454 |
D. | 123 |
Answer» C. 12454 | |
Explanation: max returns the maximum element in the list. |
88. |
Suppose list1 is [3, 5, 25, 1, 3], what is min(list1)? |
A. | 3 |
B. | 5 |
C. | 25 |
D. | 1 |
Answer» D. 1 | |
Explanation: min returns the minimum element in the list. |
89. |
Suppose list1 is [1, 5, 9], what is sum(list1)? |
A. | 1 |
B. | 9 |
C. | 15 |
D. | error |
Answer» C. 15 | |
Explanation: sum returns the sum of all elements in the list. |
90. |
To shuffle the list(say list1) what function do we use? |
A. | list1.shuffle() |
B. | shuffle(list1) |
C. | random.shuffle(list1) |
D. | random.shufflelist(list1) |
Answer» C. random.shuffle(list1) | |
Explanation: execute in the shell to verify. |
91. |
Suppose list1 is [4, 2, 2, 4, 5, 2, 1, 0], Which of the following is correct syntax for slicing operation? |
A. | print(list1[0]) |
B. | print(list1[:2]) |
C. | print(list1[:-2]) |
D. | all of the mentioned |
Answer» D. all of the mentioned | |
Explanation: slicing is allowed in lists just as in the case of strings. |
92. |
Suppose list1 is [2, 33, 222, 14, 25], What is list1[-1]? |
A. | error |
B. | none |
C. | 25 |
D. | 2 |
Answer» C. 25 | |
Explanation: -1 corresponds to the last index in the list. |
93. |
Suppose list1 is [2, 33, 222, 14, 25], What is list1[:-1]? |
A. | [2, 33, 222, 14] |
B. | error |
C. | 25 |
D. | [25, 14, 222, 33, 2] |
Answer» A. [2, 33, 222, 14] | |
Explanation: execute in the shell to verify. |
94. |
print sum |
A. | 11 |
B. | 12 |
C. | 21 |
D. | 22 |
Answer» B. 12 | |
Explanation: when assigning names1 to names2, we create a second reference to the same list. changes to names2 affect names1. when assigning the slice of all elements in names1 to names3, we are creating a full copy of names1 which can be modified independently. |
95. |
Suppose list1 = [0.5 * x for x in range(0, 4)], list1 is: |
A. | [0, 1, 2, 3] |
B. | [0, 1, 2, 3, 4] |
C. | [0.0, 0.5, 1.0, 1.5] |
D. | [0.0, 0.5, 1.0, 1.5, 2.0] |
Answer» C. [0.0, 0.5, 1.0, 1.5] | |
Explanation: execute in the shell to verify. |
96. |
To add a new element to a list we use which command? |
A. | list1.add(5) |
B. | list1.append(5) |
C. | list1.addlast(5) |
D. | list1.addend(5) |
Answer» B. list1.append(5) | |
Explanation: we use the function append to add an element to the list. |
97. |
To insert 5 to the third position in list1, we use which command? |
A. | list1.insert(3, 5) |
B. | list1.insert(2, 5) |
C. | list1.add(3, 5) |
D. | list1.append(3, 5) |
Answer» B. list1.insert(2, 5) | |
Explanation: execute in the shell to verify. |
98. |
To remove string “hello” from list1, we use which command? |
A. | list1.remove(“hello”) |
B. | list1.remove(hello) |
C. | list1.removeall(“hello”) |
D. | list1.removeone(“hello”) |
Answer» A. list1.remove(“hello”) | |
Explanation: execute in the shell to verify. |
99. |
Suppose list1 is [3, 4, 5, 20, 5], what is list1.index(5)? |
A. | 0 |
B. | 1 |
C. | 4 |
D. | 2 |
Answer» D. 2 | |
Explanation: execute help(list.index) to get details. |
100. |
Suppose list1 is [3, 4, 5, 20, 5, 25, 1, 3], what is list1.count(5)? |
A. | 0 |
B. | 4 |
C. | 1 |
D. | 2 |
Answer» D. 2 | |
Explanation: execute in the shell to verify. |
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.