<
RHD
/>
Home
Blog
Quiz
Resources
About
Contact
Enlist
// guest
▾
Login
Request Account
[ light ]
// Object-oriented programming
Object-oriented programming Quiz
// question 1 of 10
What does __init__ return?
Nothing — it always returns None
A boolean indicating success
The newly created object
// question 2 of 10
What is the purpose of __init__ versus a regular method?
__init__ runs automatically at creation while regular methods are called explicitly
__init__ cannot take arguments other than self
__init__ must always return the object
// question 3 of 10
What does __getitem__ define?
The behavior of bracket indexing on an object
The way the object is iterated
The way the object is printed
// question 4 of 10
What is an object in OOP?
An instance of a class
A variable that holds a list
A function that returns data
// question 5 of 10
What is the purpose of defining __eq__ and __hash__ together?
They must always be defined together or Python raises an error
Objects used as dictionary keys need consistent equality and hash behavior
They define the same behavior from different directions
// question 6 of 10
What is the is-a relationship in OOP?
A method is a function — used to justify encapsulation
A Dog is an Animal — used to justify inheritance
A Shelter has Animals — used to justify composition
// question 7 of 10
What keyword is used to define a class in Python?
class
object
def
// question 8 of 10
What is a namespace in OOP?
The scope in which names are defined — class namespace vs instance namespace
A list of all method names in a class
A dictionary mapping class names to their files
// question 9 of 10
What does setattr(obj, 'name', value) do?
Sets the attribute name to value on obj
Raises an error if the attribute already exists
Creates a new method on obj
// question 10 of 10
What is the has-a relationship in OOP?
An attribute has a value — used to justify encapsulation
A Shelter has Animals — used to justify composition
A Dog is an Animal — used to justify inheritance
Submit Answers →