Skip to content
Advertisement

str method not printing correctly

I’m working on creating a subclass Rug from a parent class rectangle for school.
Everything looks like it should be working but when I try to print the __str__ method for the subclass the only that populates from the parent class is <__main__.Rug object at 0x0000019C2B69C400>.

This is my Parent Class :

JavaScript

This is my Rug subclass :

JavaScript

This is all in Python 3.

This is my first time asking a question on here so if I need to provide anymore information like the code for my Rectangle parent class please let me know.

Any help would be appreciated!

Advertisement

Answer

Is a __str__(self) implemented in the base class? If assuming your Rectange looks like the following:

JavaScript

Your code would print the base function’s string representation defined by it’s __str__() function.

You could use f-string interpolation to clean up your Rug.__str__() as well:

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement