Bird
0
0

What will be the output of this code?

medium📝 Predict Output Q13 of 15
Python - Custom Exceptions
What will be the output of this code?
class Dog:
    pass

my_dog = Dog()
my_dog.age = 5
print(my_dog.age)
AAttributeError
Bage
CDog
D5
Step-by-Step Solution
Solution:
  1. Step 1: Understand attribute assignment

    The code creates an empty class Dog and an instance my_dog. Then it adds a custom attribute age with value 5 to my_dog.
  2. Step 2: Print the attribute value

    Printing my_dog.age outputs the value stored, which is 5.
  3. Final Answer:

    5 -> Option D
  4. Quick Check:

    Custom attribute value prints correctly [OK]
Quick Trick: Print attribute after assignment to see its value [OK]
Common Mistakes:
  • Expecting class name or attribute name as output
  • Thinking attribute does not exist yet
  • Confusing attribute with method call

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes