Python 3 Functions and OOPs
Python 3 Functions and OOPs
Python 3 Functions and OOPs
All
The elements of an iterator can be accessed multiple times. State if the
statement is True or False. False
The output of the expression itertools.takewhile(lambda x: x<5,
[1,4,6,4,1]) is _______. 1,4
Generators consume more space in memory than the lists. State if the
statement is True or false. False
The output of the expression { ord(i) for i in 'apple' } is _______.
A:97
Which of the following are present in a function header? Function name
and parameter list
What is the return type of function 'id'? int
The output of expression, k = [print(i) for i in "maverick" if i not
in "aeiou"] is _______. Prints all characters that are not vowels
class grandpa(object):
pass
class father(grandpa):
pass
class mother(object):
pass
print(child.__mro__)
class A:
def __init__(self, x=5, y=4):
self.x = x
self.y = y
def __str__(self):
return 'A(x: {}, y: {})'.format(self.x, self.y)
def f1():
a = A(12, 3)
b = A(3, 12)
if (a == b):
print(b != a)
print(a)
f1()
False A
def f(self):
print(float())
print(hex(-255))
class B(A):
def __init__(self):
print('two')
def f(self):
print(float())
print(hex(-42))
x = B()
x.f()
two
0.0
-0x2a
class A:
x = 0
def __init__(self):
A.x += 1
def displayCount(self):
print('Count : %d' % A.x)
def display(self):
print('a :', self.a, ' b :', self.b)
a1 = A('George', 25000)
a2 = A('John', 30000)
a3 = A()
a1.display()
a2.display()
print(A.x)
Results in Error
Which methods are invoked on entering into and exiting from the block of
code written in 'with' statement? __enter__ __exit__
class class1:
a = 1
def f1(self):
a = 2
class1.a += 1
print(class1.a, end=' ')
print(a, end=' ')
class1().f1()
class1().f1()
2232
class A:
def __init__(self, a = 5):
self.a = a
def f1(self):
self.a += 10
class B(A):
def __init__(self, b = 0):
A.__init__(self, 4)
self.b = b
def f1(self):
self.b += 10
x = B()
x.f1()
print(x.a,'-', x.b)
“4-10”
Which of the following keyword is used for creating a method inside a class
? def
Which of the following method is used by a user defined class to support '+'
operator? __add__
Which of the following statement sets the metaclass of class A to B? Class
A: __metaclass__ = B
Which of the following is not a way to import the module 'm1' or the
functions 'f1' and 'f2' defined in it? import f1, f2 from m1
Which of the following statement retreives names of all builtin module
names? import sys; sys.builtin_module_names
Which of the following module is not used for parsing command line
arguments automatically? Cmdparse
In Python, which of the following files is mandatory to treat a folder as a
package? Init.py Init.py
Which of the following modules is used to manage installtion, upgradtion,
deletion of other pacakages automatically? pip
Any Python Script can act like a Module. State if the statement is True or
False? True
Which of the following expression can be used to check if the file
'C:\Sample.txt' exists and is also a regular file? os.path.isfile(C:\Sample.txt)
Which of the following methods of 'random' module is used to pick a single
element, randomly, from a given list of elements? choice
Which of the following statement retreives names of all builtin objects?
import builtins; builtins.dict.keys()
Which methods are defined in an iterator class? Iter, next (in bold)
The output of expression [x*y for x, y in zip([3,4],[5,6])] is _______.
[15,24]
In Python, which of the following files is mandatory to treat a folder as a
package? __ init__.py
Which of the following statement is not true about Python functions? Non
keyword arguments can be passed after keyword arguments
Which of the following modules contain functions that create iterators for
efficient looping? Itertools
The output of the expression 'itertools.dropwhile(lambda x: x<5, [1,4,6,4,1])'
is _______. [6,4,1]
The output of the expression [(i.upper(), len(i)) for i in 'kiwi' ] is
_______. [('K', 1), ('I', 1), ('W', 1), ('I', 1)]
Which of the following statement retreives names of all builtin objects?
import builtins; builtins.__dict__.keys()