Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Python pavangal

Total questions: 20

Worksheet time: 15mins

Name
Class
Date
1.

In Python, polymorphism means:

a)

Same function name works with different data types

b)

Variables can store multiple values

c)

Functions are hidden from the user

d)

Only one function is allowed per program

2.

Method overriding in Python happens when:

a)

A child class defines a method with the same name as parent

b)

Two methods have the same name in the same class

c)

A class has more than one constructor

d)

A method is hidden from other classes

3.

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())

a)

Class A

b)

Class B

c)

Error

d)

None

4.

Abstraction in Python is implemented using:

a)

os module

b)

abc module

c)

math module

d)

random module

5.

What happens if we don’t implement all abstract methods in a subclass?

a)

Subclass becomes abstract itself

b)

Python will run without issues

c)

Methods are ignored

d)

Default implementations are provided

6.

Can we create an object of an abstract class directly in Python?

a)

Yes, always

b)

No

c)

Only with multiple inheritance

d)

Only if it has one abstract method

7.

An algorithm is:

a)

A Python library

b)

A set of step-by-step instructions to solve a problem

c)

A built-in function

d)

A variable name

8.

The time complexity of searching in a Python list using in is:

a)

O(1)

b)

O(n)

c)

O(log n)

d)

O(n²)

9.

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())

a)

Error

b)

78.5

c)

None

d)

Abstract class can’t be inherited

10.

What is the time complexity of inserting at the beginning of a Python list?

a)

O(1)

b)

O(n)

c)

O(log n)

d)

O(n log n)

11.

What will this code output?

arr = [3, 1, 4, 1, 5]

print(sorted(arr, reverse=True))

a)

[1, 1, 3, 4, 5]

b)

[5, 4, 3, 1, 1]

c)

[3, 1, 4, 1, 5]

d)

Error

12.

Which sorting algorithm repeatedly swaps adjacent elements if they are in the wrong order?

a)

Merge Sort

b)

Quick Sort

c)

Bubble Sort

d)

Selection Sort

13.

A class in which one or more methods are only implemented to raise an exception is called an abstract class.

a)

True

b)

False

c)

Both True and False

d)

None

14.

What is the biggest reason for the use of polymorphism?

a)

It allows the programmer to think at a more abstract level

b)

There is less program code to write

c)

The program will have a more elegant design and will be easier to maintain and update

d)

Program code takes up less space

15.

Private members of a class cannot be accessed.

a)

True

b)

False

c)

Both True and False

d)

None of the above

16.

Which of the following statements is true?

a)

The new() method automatically invokes the init method

b)

The init method is defined in the object class

c)

The __eq() method is defined in the object class

d)

The repr() method is defined in the object class

17.

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()

a)

test of B called

test of C called

b)

test of C called

test of B called

c)

test of B called

d)

Error, both the classes from which D derives has same method test()

18.

How many except statements can a try-except block have?

a)

zero

b)

one

c)

more than one

d)

more than zero

19.

What does print(Test.__name__) display (assuming Test is the name of the class)?

a)

()

b)

Exception is thrown

c)

Test

d)

main

20.

Draw your favourite anime character and mention their name