wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Quiz 05 - Python Objects

Total questions: 22

Worksheet time: 5mins

Name
Class
Date
1.
Last name, First name Middle Initial
4 lines
2.
Gender
a)
Male
b)
Female
3.

1. What is a class in in Python?

a)

a) A variable that holds data

b)

b) A template for creating objects

c)

c) A built-in function

d)

d) A type of loop

4.

2. Which method is automatically called when an object is created?

a)

a) __del__

b)

b) __main__

c)

c) __init__

d)

d) __str__

5.

3. What does self represent in a class method?

a)

a) The parent class

b)

b) The instance of the class

c)

c) A reserved keyword for inheritance

d)

d) A reference to the class itself

6.

4. Which keyword is used to inherit from a parent class?

a)

a) extends

b)

b) inherit

c)

c) super

d)

d) Parentheses in the class definition

7.

5. What is the output of the code below? print(type([]))

a)

a)

b)

b)

c)

c)

d)

d)

8.

6. Which statement about instance attributes is true?

a)

a) They are shared across all instances of a class.

b)

b) They are defined outside the __init__ method.

c)

c) They are unique to each object.

d)

d) They cannot be modified after creation.

9.

7. What does the dir(obj) function return?

a)

a) The documentation string of obj

b)

b) A list of obj’s attributes and methods

c)

c) The memory address of obj

d)

d) The parent class of obj

10.

8. Which code correctly creates an instance of a class Dog?

a)

a) Dog.create()

b)

b) Dog.__init__()

c)

c) Dog()

d)

d) new Dog()

11.

9. What is the purpose of a destructor (__del__)?

a)

a) Initialize object attributes

b)

b) Delete an object’s methods

c)

c) Clean up resources before an object is destroyed

d)

d) Prevent inheritance

12.

10. Which class definition demonstrates inheritance?

a)

a) class Car: pass

b)

b) class Tesla(Car): pass

c)

c) class Engine: pass

d)

d) class Car(Tesla): pass

13.

11. A class can have multiple constructors in Python

a)

True

b)

False

14.

12. Instance attributes override class attributes with the same name

a)

True

b)

False

15.

13. The __del__ method is commonly used in production code

a)

True

b)

False

16.

14. All methods in a class must include self as the first parameter.

a)

True

b)

False

17.

15. Inheritance allows a subclass to inherit private attributes from its parent

a)

True

b)

False

18.

16. The (a)   method is used to initialize an object’s state.

19.

17. Write the syntax for creating a subclass Dog inheriting from class Animal.

(a)  

20.

18. What does the following code output?

(a)  

21.

19. The function (a)   lists all attributes and methods of an object.

22.

20. Write the command to check the capabilities (methods and attributes) of an object obj.

(a)