WorksheetsPython pavangal
Total questions: 20
Worksheet time: 15mins
In Python, polymorphism means:
Same function name works with different data types
Variables can store multiple values
Functions are hidden from the user
Only one function is allowed per program
Method overriding in Python happens when:
A child class defines a method with the same name as parent
Two methods have the same name in the same class
A class has more than one constructor
A method is hidden from other classes
What will this code output?
class A:
def show(self): return "Class A"
class B(A):
def show(self): return "Class B"
obj = B()
print(obj.show())
Class A
Class B
Error
None
Abstraction in Python is implemented using:
os module
abc module
math module
random module
What happens if we don’t implement all abstract methods in a subclass?
Subclass becomes abstract itself
Python will run without issues
Methods are ignored
Default implementations are provided
Can we create an object of an abstract class directly in Python?
Yes, always
No
Only with multiple inheritance
Only if it has one abstract method
An algorithm is:
A Python library
A set of step-by-step instructions to solve a problem
A built-in function
A variable name
The time complexity of searching in a Python list using in is:
O(1)
O(n)
O(log n)
O(n²)
What will be the result of this code?
from abc import ABC, abstractmethod
class Shape(ABC):
@abstractmethod
def area(self): pass
class Circle(Shape):
def init(self, r): self.r = r
def area(self): return 3.14 self.r self.r
c = Circle(5)
print(c.area())
Error
78.5
None
Abstract class can’t be inherited
What is the time complexity of inserting at the beginning of a Python list?
O(1)
O(n)
O(log n)
O(n log n)
What will this code output?
arr = [3, 1, 4, 1, 5]
print(sorted(arr, reverse=True))
[1, 1, 3, 4, 5]
[5, 4, 3, 1, 1]
[3, 1, 4, 1, 5]
Error
Which sorting algorithm repeatedly swaps adjacent elements if they are in the wrong order?
Merge Sort
Quick Sort
Bubble Sort
Selection Sort
A class in which one or more methods are only implemented to raise an exception is called an abstract class.
True
False
Both True and False
None
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
Private members of a class cannot be accessed.
True
False
Both True and False
None of the above
Which of the following statements is true?
The new() method automatically invokes the init method
The init method is defined in the object class
The __eq() method is defined in the object class
The repr() method is defined in the object class
What will be the output of the following Python code?
class A:
def test1(self):
print(" test of A called ")
class B(A):
def test(self):
print(" test of B called ")
class C(A):
def test(self):
print(" test of C called ")
class D(B,C):
def test2(self):
print(" test of D called ")
obj=D()
obj.test()
test of B called
test of C called
test of C called
test of B called
test of B called
Error, both the classes from which D derives has same method test()
How many except statements can a try-except block have?
zero
one
more than one
more than zero
What does print(Test.__name__) display (assuming Test is the name of the class)?
()
Exception is thrown
Test
main
Draw your favourite anime character and mention their name

