wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Week 7-8

Total questions: 30

Worksheet time: 15mins

Name
Class
Date
1.

What is method overriding?

a)

Changing the way a method works in a subclass.

b)

Increasing the speed of a method.

c)

Deleting a method from a superclass.

d)

Renaming a method in a subclass.

2.

What is association in Python?

a)

Error handling technique.

b)

Relationship between classes where one class uses the functionalities of another class.

c)

A special method in Python.

d)

A way to import libraries.

3.

What does the method _init_ do in Python classes?

a)

Initializes a newly created object.

b)

Acts as a destructor for objects.

c)

Is called when an object is inherited.

d)

Initializes static variables.

4.

What does the 'super()' function do?

a)

It enhances the speed of functions.

b)

It is used to call a method from a sibling class.

c)

It returns a proxy object that delegates method calls to a parent or sibling class.

d)

It is used to terminate a program.

5.

Which statement about method overloading in Python is true?

a)

Python does not support method overloading by default.

b)

Method overloading is the same as method overriding.

c)

Python requires a special operator for method overloading.

d)

Method overloading can only be done in subclasses.

6.

How do you define a private variable in a Python class?

a)

By using the private keyword.

b)

By prefixing the variable name with two underscores __.

c)

By prefixing the variable name with a single underscore _.

d)

By using the private method.

7.

Can a Python class inherit from multiple classes?

a)

Yes, but only if the classes are abstract.

b)

No, Python supports only single inheritance.

c)

Yes, Python supports multiple inheritance.

d)

No, this feature is not available in Python.

8.

What is the purpose of the _str_ method in Python?

a)

It is used for adding two objects together.

b)

It is used to return a string representation of an object.

c)

It is used to compare two objects.

d)

It initializes an object.

9.

How can you access a base class method from a derived class that has overridden the method?

a)

By calling base_class.method_name().

b)

By renaming the base class method.

c)

 By calling method_name() without any prefix.

d)

By calling super().method_name().

10.

Which of the following is an advantage of using inheritance?

a)

Increased code complexity.

b)

Reduced code reusability.

c)

Increased memory usage.

d)

Code reusability and extensibility.

11.

Which of the following is not a principle of object-oriented programming?

a)

Inheritance

b)

Encapsulation

c)

Polymorphism

d)

Multiprocessing

12.

What is the output of 'isinstance(obj, Class)' if obj is an instance of Class?

a)

Error

b)

0

c)

1

d)

True

13.

Which keyword is used for inheritance in Python?

a)

inherit

b)

extends

c)

import

d)

class

14.

What does polymorphism mean in the context of object-oriented programming?

a)

The ability to take on multiple forms.

b)

The process of inheriting a class from another class.

c)

The concept of restricting access to methods.

d)

A function without a name.

15.

If Class B inherits from Class A, which is true?

a)

Class A is the superclass and Class B is the subclass.

b)

Class B is the superclass and Class A is the subclass.

c)

Both classes are superclasses.

d)

Both classes are subclasses.

16.

What is a module in Python?

a)

A code library consisting of Python classes.

b)

A single Python script that can be used in other Python scripts.

c)

A built-in Python function.

d)

A Python version management tool.

17.

How do you import a module named math?

a)

import math

b)

include math

c)

#import math

d)

module math

18.

What is the correct syntax to import only the sqrt function from the math module?

a)

import sqrt from math

b)

from math import sqrt

c)

import math.sqrt

d)

load sqrt from math

19.

Which of the following is a package in Python?

a)

A collection of Python modules.

b)

A type of Python function.

c)

A module with a single script.

d)

A Python compiler.

20.

How do you create a package in Python?

a)

By compiling multiple Python scripts.

b)

By creating a directory with an init.py file.

c)

By declaring a package keyword in a Python script.

d)

By installing Python packages manager.

21.

What is the purpose of the _init_.py file in Python packages?

a)

To initialize Python when you start your computer.

b)

To declare that a directory is a Python package.

c)

To automatically execute a script when Python starts.

d)

To define initialization parameters for Python scripts.

22.

Which statement is true about the sys.path list in Python?

a)

It contains the names of built-in modules.

b)

It specifies the interpreter path.

c)

It lists directories Python will search for modules.

d)

It is a Python module for system-level operations.

23.

What is the purpose of unit testing in Python?

a)

To compile Python code faster.

b)

To check the performance of Python scripts.

c)

To ensure that individual units of code work as expected.

d)

To increase Python code execution speed.

24.

Which module is used for unit testing in Python?

a)

unittest

b)

pytest

c)

Test

d)

unit

25.

How do you run tests in a module named test_module?

a)

python -m unittest test_module

b)

run test_module.tests

c)

python test_module --test

d)

test -m python test_module

26.

What does importing a package automatically import?

a)

Everything in the package and subpackages.

b)

Only modules listed in the package's init.py file.

c)

Nothing; you must import each module explicitly.

d)

Only the init.py file.

27.

What is the best practice for naming test files in Python?

a)

Start with test_ followed by the module name.

b)

End with _test followed by the module name.

c)

Files should not include the word test.

d)

Use the module name followed by the word files.

28.

Which statement is correct about the from module import * syntax?

a)

It is recommended for clarity and avoiding namespace issues.

b)

It imports only the functions explicitly defined in the module.

c)

It can lead to conflicts in the namespace due to overlapping names.

d)

It is the most memory-efficient way to import modules.

29.

How do you reload a module named module_name?

a)

reload(module_name)

b)

importlib.reload(module_name)

c)

pip reload module_name

d)

python -m reload module_name

30.

What is the output of importing a module for the first time?

a)

The module is compiled into machine code.

b)

The module's code is executed.

c)

The module is only checked for syntax errors.

d)

A new module file is created.