Predict Class Instance Output
Predict Output Medium
Question
What does this code print?
Code
class Dog:
def __init__(self, name):
self.name = name
def bark(self):
return f"{self.name} says Woof!"
d = Dog("Rex")
print(d.bark())
Hint
__init__ sets self.name, bark uses it.
Explanation
Dog("Rex") creates an instance with self.name = "Rex". d.bark() returns f"{self.name} says Woof!" = "Rex says Woof!". Output: Rex says Woof!
Related Resources
Related Lessons
- Classes and Objects
Class instances.
Look up unfamiliar terms
A beginner-friendly glossary explains jargon in plain English — variables, functions, DOM, Promise, and more.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.
Build real projects
Apply what you learned by building guided projects with starter code and solutions.