This lesson will show you why you would want to control how a Python class is represented. In the lesson, you’ll create a Python class and see what happens when you try to print out one of its instances to the console. The result of doing this is relatively unsatisfying.
Course Intro & Example Python Class
And what you can see is that when I print this
Car object, we kind of get this unsatisfying result, and it’s the same when I just inspect the object in this interpreter session. So you can see here, well, at least it gives us the class name—kind of the whole namespace of this thing—but it only gives us the memory address if we’re on CPython, you know, it just gives us this ID. And it’s kind of opaque and kind of hard to understand what’s going on. So, this is better than nothing, but it’s not super useful.
Become a Member to join the conversation.