__class__

This is not a method, but rather an attribute—and there is no need to overwrite it. Python automatically stores the class that the instance is built upon under that alias. It comes in handy if you want to create a new instance of the same class from within the instance but don't want to explicitly specify the class itself:

>>> S.__class__
__main__.School

The great part is that if you'll later inherit from the class that uses this attribute, a new wrapping class will be returned. We'll use __class__ later in this chapter.

Here, we mentioned inheritance, but we haven't yet discussed it. Let's do that right now!

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.218.3.111