Encapsulation, inheritance and polymorphism

Steven D'Aprano steve+comp.lang.python at pearwood.info
Thu Jul 19 03:22:35 CEST 2012

On Thu, 19 Jul 2012 01:04:50 +1000, Chris Angelico wrote:

> Python isn't object oriented in the way Java is ("EVERYTHING has to be
> in a class! Look, it's all OO now!").

Actually, Python is more object-oriented than Java. In Python, everything 
is an object. We have no distinction between boxed and unboxed integers, 
for example -- all integers are boxed, always.

(Of course, data structures written in C, for example the array type, can 
encapsulate unboxed native ints. But the array itself is still an object.)

On the other hand, Python doesn't force you to program using an object-
oriented style. If you want to write functional code like Haskell, you 
can. If you want to write Pascal-style procedural code, you can. If you 
prefer an imperative style closer to shell scripting, go right ahead. The 
only one of the major paradigms that Python doesn't naturally support is 
logic programming.

So Python is simultaneously more *and* less object-oriented than Java.


More information about the Python-list mailing list