0% found this document useful (0 votes)
67 views

FrescoPlay Python Functions and OOP

The document discusses Python concepts like functions, OOP, exceptions, modules and various other topics. It provides questions related to these topics along with their answers. Multiple choice, code snippets and their outputs are given.

Uploaded by

Sai Praveen
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
67 views

FrescoPlay Python Functions and OOP

The document discusses Python concepts like functions, OOP, exceptions, modules and various other topics. It provides questions related to these topics along with their answers. Multiple choice, code snippets and their outputs are given.

Uploaded by

Sai Praveen
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

The output of the expression { ord(i) for i in 'apple' } is _______.

- — {97, 112,
108, 101}

The output of the expression itertools.takewhile(lambda x: x<5, [1,4,6,4,1]) is


_______.—-[1,4]
The elements of an iterator can be accessed multiple times. State if the
statement is True or False. — False

What is the return type of function 'id'? --- int

The output of the expression [ chr(i) for i in [65, 66, 67] ] is _______. —[‘A’, 'B',
'C']
Which of the following types of arguments can be passed to a function? — All the
options mentioned

What is the default return value of a Python function? — None

A generator function can have multiple yield expressions. State if the statement is
True or False. — True

Which of the following are present in a function header? — function name and
parameter list

The output of the expression {0 if i%2 ==0 else 1 for i in range(8)} is _______. —
{0, 1}

What is the output of the following code?

class A:
def __init__(self, a = 5):
self.a = a

This study source was downloaded by 100000839484608 from CourseHero.com on 01-05-2022 21:38:31 GMT -06:00

https://www.coursehero.com/file/79021425/FrescoPlay-Python-Functions-and-OOPrtf/
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 method is used by a user


defined class to support '+' operator? — __add__

What is the output of the following code?

class A:
x = 0

def __init__(self, a, b):


self.a = a
self.b = b
A.x += 1

def __init__(self):
A.x += 1

def displayCount(self):

This study source was downloaded by 100000839484608 from CourseHero.com on 01-05-2022 21:38:31 GMT -06:00

https://www.coursehero.com/file/79021425/FrescoPlay-Python-Functions-and-OOPrtf/
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__

What is the output of the following code?

class grandpa(object):
pass

class father(grandpa):
pass

class mother(object):
pass

class child(mother, father):


pass

This study source was downloaded by 100000839484608 from CourseHero.com on 01-05-2022 21:38:31 GMT -06:00

https://www.coursehero.com/file/79021425/FrescoPlay-Python-Functions-and-OOPrtf/
print(child.__mro__)

(<class '__main__.child'>, <class '__main__.mother'>, <class


'__main__.father'>,
<class '__main__.grandpa'>, <class 'object'>)

Which of the following keyword is used for creating


a method inside a class ? —def

Which of the following statement sets the


metaclass of class A to B?

class A:
__metaclass__ = B

What is the output of the following code?

class class1:
a = 1

def f1(self):
a = 2
class1.a += 1
print(class1.a, end=' ')
print(a, end=' ')

class1().f1()
class1().f1()

2232

This study source was downloaded by 100000839484608 from CourseHero.com on 01-05-2022 21:38:31 GMT -06:00

https://www.coursehero.com/file/79021425/FrescoPlay-Python-Functions-and-OOPrtf/
What is the output of the following code?

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 __eq__(self, other):


return self.x * self.y == other.x * other.y

def f1():
a = A(12, 3)
b = A(3, 12)
if (a == b):
print(b != a)
print(a)

f1()

False
A(x: 12, y: 3)

Whta is the output of the following code ?

class A:
def __init__(self):
print('one')

def f(self):
print(float())

This study source was downloaded by 100000839484608 from CourseHero.com on 01-05-2022 21:38:31 GMT -06:00

https://www.coursehero.com/file/79021425/FrescoPlay-Python-Functions-and-OOPrtf/
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

How many except statements can a try-except


block have? — more than zero
In which of the following scenarios, finally block is
executed? —always

Which of the following execption occurs, when an


undefined object is accessed? —NameError

Which of the following exception occurs, when an


integer object is added to a string object? —
TypeError

When will the else part of try-except-else be


executed? —when no exception occurs

This study source was downloaded by 100000839484608 from CourseHero.com on 01-05-2022 21:38:31 GMT -06:00

https://www.coursehero.com/file/79021425/FrescoPlay-Python-Functions-and-OOPrtf/
Which of the following execption occurs, when a
number is divided by zero?—ZeroDivisionError

Which of the keyword is used to display a


customised error message to the user? —raise
Can one block of except statements handle multiple
exception? — No, Multiple exceptions cannot be handled in a
single block

If a list has 5 elements, then which of the following


exceptions is raised when 8th element is accessed?
—IndexError

Which of the following execption occurs, when an


undefined object is accessed?—NameError

The output of the expression '2' == 2 is _________.


—False

In Python, which of the following files is mandatory


to treat a folder as a package?—init.py
Which of the following modules are used to deal
with Data compression and archiving?—All of those
mentioned
Which of the following modules is used to manage
installtion, upgradtion, deletion of other pacakages
automatically? —pip

Which of the following is not a way to import the

This study source was downloaded by 100000839484608 from CourseHero.com on 01-05-2022 21:38:31 GMT -06:00

https://www.coursehero.com/file/79021425/FrescoPlay-Python-Functions-and-OOPrtf/
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 objects?—import builtins; builtins.dict.keys()
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 statement retreives names


of all builtin module names?—import sys;
sys.builtin_module_names
Any Python Script can act like a Module. State if
the statement is True or False?—True
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 brackets are used to define
a set comprehension? —{}
Which of the following function call is correct?—
f(a=1, b=1, c=2)
The output of the expression {i:j for i in "abcd"
for j in "kiwi"} is _______.—{'a': 'i', 'd': 'i', 'c': 'i', 'b': 'i'}
Which keyword is used for defining a function? —
def
Which of the following variables stores
documentation of a function?—docstr
How are variable length keyword arguments
specified in the function heading?—one star followed by

This study source was downloaded by 100000839484608 from CourseHero.com on 01-05-2022 21:38:31 GMT -06:00

https://www.coursehero.com/file/79021425/FrescoPlay-Python-Functions-and-OOPrtf/
a valid identifier
The output of expression [i**+1 for i in
range(3)] is _______. —[0, 1, 2]

This study source was downloaded by 100000839484608 from CourseHero.com on 01-05-2022 21:38:31 GMT -06:00

https://www.coursehero.com/file/79021425/FrescoPlay-Python-Functions-and-OOPrtf/
Powered by TCPDF (www.tcpdf.org)

You might also like