- 1
- 2
- 3
- 4
- Next Page »
A Learning Portal from Recruitment India
What is the biggest reason for the use of polymorphism?
It allows the programmer to think at a more abstract level
There is less program code to write
The program will have a more elegant design and will be easier to maintain and update
Program code takes up less space
Answer with explanation
Answer: Option CExplanation
Polymorphism allows for the implementation of elegant software.
Workspace
Which of the following is false about protected class members?
They begin with one underscore
They can be accessed by subclasses
They can be accessed within a class
They can be accessed by name mangling method
Answer with explanation
Answer: Option DExplanation
Protected class members can’t be accessed by name mangling
Workspace
To read the entire remaining contents of the file as a string from a file object infile, we use ____________
infile.read(2)
infile.read()
infile.readline()
infile.readlines()
Answer with explanation
Answer: Option BExplanation
read function is used to read all the lines in a file.
Workspace
What will be the output of the following Python code?
def c(f):
def inner(*args, **kargs):
inner.co += 1
return f(*args, **kargs)
inner.co = 0
return inner
@c
def fnc():
pass
if __name__ == ‘__main__’:
fnc()
fnc()
fnc()
print(fnc.co)
4
3
1
Answer with explanation
Answer: Option BExplanation
The code shown above returns the number of times a given function has been called. Hence the output of this code is: 3
Workspace
The formatting method {1:<10} represents the ___________ positional argument, _________ justified in a 10 character wide field.
second, right
first, left
second, left
first, right
Answer with explanation
Answer: Option CExplanation
The formatting method {1:<10} represents the second positional argument, left justified in a 10 character wide field.
Workspace
Which of the following Boolean expressions is not logically equivalent to the other three?
not(-6<0 or-6>10)
not(-6>10 or-6==10)
not(-6<10 or-6==10)
-6>=0 and -6<=10
Answer with explanation
Answer: Option BExplanation
The expression not(-6<0 or -6>10) returns the output False.
The expression -6>=0 and -6<=10 returns the output False.
The expression not(-6<10 or -6==10) returns the output False.
The expression not(-6>10 or -6==10) returns the output True.
Workspace
Which of the following is the truncation division operator?
/
|
%
//
Answer with explanation
Answer: Option DExplanation
// 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.
Workspace
Which of the following function gets a space-padded string with the original string left-justified to a total of width columns?
isupper()
join(seq)
len(string)
ljust(width[, fillchar])
Answer with explanation
Answer: Option DExplanation
ljust(width[, fillchar]) − Returns a space-padded string with the original string left-justified to a total of width columns.
Workspace
How will you not create a dictionary?
d = {‘milk’: 50, ‘celery’: 40}
d = dict(milk=50, celery=40)
d = dict([ (‘milk’, 50), (‘celery’, 40) ])
d = { (‘milk’, 50), (‘celery’, 40) }
Answer with explanation
Answer: Option DExplanation
d = { (‘milk’, 50), (‘celery’, 40) } creates a set, not a dictionary.
Workspace
What is the output of the function shown below (random module has already been imported)?
random.choice(‘sun’)
sun
u
either s, u or n
error
Answer with explanation
Answer: Option CExplanation
The above function works with alphabets just as it does with numbers. The output of these expressions will be either s, u, and n.
Workspace
Which of these is false about recursion?
Recursive function can be replaced by a non-recursive function
Recursive functions usually take more memory space than non-recursive function
Recursive functions run faster than non-recursive function
Recursion makes programs easier to understand
Answer with explanation
Answer: Option CExplanation
The speed of a program using recursion is slower than the speed of its non-recursive equivalent.
Workspace
What is the output of the following piece of code?
def a(b):
b = b + [5]
c = [1, 2, 3, 4]
a(c)
print(len(c))
4
5
1
An Exception is thrown
Answer with explanation
Answer: Option BExplanation
Since a list is mutable, any change made in the list in the function is reflected outside the function.
Workspace
What is the output of the following?
print(‘a’.maketrans(‘ABC’, ‘123’))
{97: 49, 98: 50, 99: 51}
{65: 49, 66: 50, 67: 51}
{97: 49}
1
Answer with explanation
Answer: Option AExplanation
maketrans() is a static method so it’s behaviour does not depend on the object from which it is being called.
Workspace
In the following options which are python libraries which are used for data analysis and scientific computations
Answer with explanation
Answer: Option DExplanation
Numpy, Scipy, pandas are few libraries in python which are used for data analysis and scientific computations.
Workspace
What will be the output of the following Python code?
odd=lambda x: bool(x%2)
numbers=[n for n in range(10)]
print(numbers)
n=list()
for i in numbers:
if odd(i):
continue
else:
break
[0,2,4,6,8,10]
[0,1,2,3,4,5,6,7,8,9]
[1,3,5,7,9]
Error
Answer with explanation
Answer: Option BExplanation
the code shown above returns a new list containing whole numbers up to 10(excluding 10). Hence the output of the code is : [0, 1, 2, 3, 4, 5, 6, 7, 8, 9].
Workspace
Which of these is the definition for packages in Python?
A number of files containing Python definitions and statements
A set of main modules
A set of programs making use of Python modules
A folder of python modules
Answer with explanation
Answer: Option DExplanation
A folder of python programs is called as a package of modules.
Workspace
Which of the following is true about the top-down design process?
The details of program design are addressed before the overall design
The overall design of the program is addressed before the details
Only the design of the program is addressed
Only the details of the program are addressed
Answer with explanation
Answer: Option BExplanation
Top-down design is an approach for deriving a modular design in which the overall design.
Workspace
Which of the following is true for variable names in Python?
unlimited length
all private members must have leading and trailing underscores
underscore and ampersand are the only two special characters allowed
none of the mentioned
Answer with explanation
Answer: Option AExplanation
unlimited length
Workspace
What is the output of the following?
print(‘abcd’.translate({‘a’: ‘1’, ‘b’: ‘2’, ‘c’: ‘3’, ‘d’: ‘4’}))
1234
abcd
error
none of the mentioned
Answer with explanation
Answer: Option BExplanation
The function translate expects a dictionary of integers. Use maketrans() instead of doing the above
Workspace