Home > Articles > Open Source > Python

  • Print
  • + Share This
This chapter is from the book

This chapter is from the book

4.15 Wrap-Up

In this chapter, we've seen the object-oriented features of Python. Python provides the essentials: classes, methods, and inheritance—indeed, multiple inheritance.

Python diverges from many other object-oriented languages in several ways:

  • No visibility restrictions: Python does not provide private, or other limited scopes, of attributes and methods. This means that encapsulation cannot be enforced, but must be programmed on the honor system. Name mangling can be used to indicate which methods and attributes are intended to be private, but it doesn't make them invisible or prevent access to them.

  • Absence of overloading: Python does not permit one of several methods with the same name to be called, depending on the numbers and types of parameters.

  • The diamond inheritance anomaly: Because of its strictly depth-first search for methods, Python allows a method in a superclass to override one in a subclass, rather than only allowing methods in subclasses to override methods from superclasses.

  • A single pool of instance attributes: All attributes used by all the classes in an inheritance hierarchy are put in a single dictionary. Attribute name collisions are a likely source of bugs. Name mangling can make it a bit easier to keep separate the attributes intended to be private.

  • + Share This
  • 🔖 Save To Your Account