WorksheetsPython Parithabangal 2.0
Total questions: 25
Worksheet time: 17mins
_____ represents an entity in the real world with its identity and behaviour.
A method
An object
A class
An operator
What will be the output of the following Python code?
class test:
def init(self,a="Hello World"):
self.a=a
def display(self):
print(self.a)
obj=test()
obj.display()
The program has an error because constructor can’t have default arguments
Nothing is displayed
“Hello World” is displayed
The program has an error display function doesn’t have parameters
What is setattr() used for?
To access the attribute of the object
To set an attribute
To check if an attribute exists or not
To delete an attribute
What will be the output of the following Python code?
class change:
def init(self, x, y, z):
self.a = x + y + z
x = change(1,2,3)
y = getattr(x, 'a')
setattr(x, 'a', y+1)
print(x.a)
6
7
Error
0
What will be the output of the following Python code?
class fruits:
def init(self, price):
self.price = price
obj=fruits(50)
obj.quantity=10
obj.bags=2
print(obj.quantity+len(obj.__dict__))
12
52
13
60
Which of the following is not a class method?
Non-static
Static
Bounded
Unbounded
What will be the output of the following Python code?
class demo():
def repr(self):
return '__repr__ built-in function called'
def str(self):
return '__str__ built-in function called'
s=demo()
print(s)
Error
Nothing is printed
str built-in function called
repr built-in function called
A ________ is a description of a set of objects that share the same attributes, operations, relationships, and semantics.
Structure
Class
Constructor
Function
What will be the output of the following Python code?
class A():
def disp(self):
print("A disp()")
class B(A):
pass obj = B()
obj.disp()
Invalid syntax for inheritance
Error because when object is created, argument must be passed
Nothing is printed
A disp()
Which of the following is not a type of inheritance?
Double-level
Multi-level
Single-level
Multiple
What type of inheritance is illustrated in the following Python code?
class A():
pass
class B():
pass
class C(A,B):
pass
Multi-level inheritance
Multiple inheritance
Hierarchical inheritance
Single-level inheritance
What will be the output of the following Python code?
class A:
def init(self):
self.__i = 1
self.j = 5
def display(self):
print(self.__i, self.j)
class B(A):
def init(self):
super().__init__()
self.__i = 2
self.j = 7
c = B()
c.display()
2 7
1 5
1 7
2 5
Which of these is a private data field?
def Demo:
def init(self):
a = 1
self.b = 1
self.__c__ = 1
d= 1
__a
__b
c
d
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 by name mangling method
They can be accessed within a class
Which operator is overloaded by invert()?
!
~
^
–
What will be the output of the following Python code?
x = ['ab', 'cd']
print(list(map(list, x)))
[‘a’, ‘b’, ‘c’, ‘d’]
[[‘ab’], [‘cd’]]
[[‘a’, ‘b’], [‘c’, ‘d’]]
none of the mentioned
What will be the output of the following Python code?
x = [12, 34]
print(len(list(map(len, x))))
2
1
error
none of the mentioned
Which of the following statements is true?
A non-private method in a superclass can be overridden
A subclass method can be overridden by the superclass
A private method in a superclass can be overridden
Overriding isn’t possible in Python
What will be the output of the following Python code?
def san(x):
print(x+1)
x=-2
x=4
san(12)
13
10
2
5
What will be the output of the following Python code?
x=12
def f1(a,b=x):
print(a,b)
x=15
f1(4)
Error
12 4
4 12
4 15
Read the following Python code carefully and point out the global variables?
y, z = 1, 2
def f():
global x
x = y+z
x
y and z
x, y and z
Neither x, nor y, nor z
Who developed Python Programming Language?
Wick van Rossu
Rasmus Lerdorf
Guido van Rossum
Mr. Harirajan
Which type of Programming does Python support?
object-oriented programming
structured programming
functional programming
all of the mentioned
Is Python code compiled or interpreted?
Python code is both compiled and interpreted
Python code is neither compiled nor interpreted
Python code is only interpreted
Python code is only compiled
Draw the Python Logo

