Last Updated: January 3, 2026
31 quizzes
Complete the code so that creating a User instance automatically prints its readable description.
print(User("Ana", 30).())Click an option to fill the blank:
Complete the expression to access the shared tax_rate defined on the Invoice class.
total_with_tax = subtotal * Invoice.Click an option to fill the blank:
Complete the code to call a class method that creates a Product from a JSON string.
product = Product.(json_data)Click an option to fill the blank:
In OOP, what does encapsulation primarily help you achieve in Python classes?
What is an object in Python OOP terms?
Which of the following is TRUE about the __init__ method?
Which statement about instance attributes is correct?
What happens if you change a class attribute on the class object itself?
Which best describes an instance method in Python?
How is a class method different from an instance method?
When is using a static method most appropriate?
Why is self explicitly included as the first parameter of instance methods?
What does the @property decorator allow you to do?
Which is a common reason to use a setter with @property?
Which built-in function calls the __repr__ method on an object?
What is operator overloading in Python?
Order the steps to define a class with __init__ that stores a user's email and then create an instance.
Drag and drop to reorder, or use the arrows.
Order the steps to add a @property that exposes a full_name attribute built from first_name and last_name.
Drag and drop to reorder, or use the arrows.
What is the output of this code?
1class Counter:
2 total = 0
3
4 def __init__(self):
5 Counter.total += 1
6
7c1 = Counter()
8c2 = Counter()
9print(Counter.total)What is the output of this code involving __str__?
1class Task:
2 def __init__(self, title):
3 self.title = title
4
5 def __str__(self):
6 return f"Task: {self.title}"
7
8job = Task("Backup")
9print(job)What does this code print when using a @property for area?
1class Square:
2 def __init__(self, side):
3 self._side = side
4
5 @property
6 def area(self):
7 return self._side * self._side
8
9s = Square(4)
10print(s.area)What is the output of this operator overloading example?
1class Score:
2 def __init__(self, value):
3 self.value = value
4
5 def __add__(self, other):
6 return Score(self.value + other.value)
7
8 def __repr__(self):
9 return f"Score({self.value})"
10
11s1 = Score(10)
12s2 = Score(5)
13print(s1 + s2)What is printed by this class and instance attribute combination?
1class Device:
2 status = "offline"
3
4 def __init__(self, status=None):
5 if status is not None:
6 self.status = status
7
8a = Device()
9b = Device("online")
10print(a.status)Find the bug in this code that tries to use a class method as an alternative constructor.
Click on the line(s) that contain the bug.
class Report: def __init__(self, title): self.title = title def from_markdown(cls, markdown_text): title_line = markdown_text.splitlines()[0] clean_title = title_line.lstrip('# ').strip() return cls(clean_title) r = Report.from_markdown("# Sales Report")Find the bug related to getters and setters using @property.
Click on the line(s) that contain the bug.
class Temperature: def __init__(self, celsius): self._celsius = celsius @property def celsius(self): return self._celsius @celsius.setter def celsius(self, value): if value < -273.15: raise ValueError("Too cold") celsius = value t = Temperature(20)t.celsius = 25Match each OOP concept to its best description.
Click an item on the left, then click its match on the right. Click a matched item to unmatch.
Match each dunder method to what it customizes.
Click an item on the left, then click its match on the right. Click a matched item to unmatch.
Complete the code so the class uses a @property to expose a read-only full_name built from first and last names.
class Member: def __init__(self, first_name, last_name): self._first_name = first_name self._last_name = last_name def full_name(self): return + " " + person = Member("Ada", "Lovelace")label = person.full_nameClick an option to fill blank 1:
Complete the code so purchases_count is a class-level counter updated each time a new Order is created via the class method.
class Order: purchases_count = 0 def __init__(self, product): self.product = product def from_product(cls, product): .purchases_count += 1 return cls(product)order1 = Order.from_product("Book")order2 = Order.from_product("Pen")Click an option to fill blank 1:
Click the line where the class attribute discount is being accessed.
Click on the line to select.
class Invoice: discount = 0.1 def __init__(self, total): self.total = total bill = Invoice(200)final_amount = bill.total * (1 - Invoice.discount)print(final_amount)Click the line where operator overloading for equality is defined.
Click on the line to select.
class Point: def __init__(self, x, y): self.x = x self.y = y def __eq__(self, other): return self.x == other.x and self.y == other.y p1 = Point(1, 2)p2 = Point(1, 2)print(p1 == p2)