Encapsulation, inheritance and polymorphism

Roy Smith roy at panix.com
Tue Jul 17 15:52:59 CEST 2012

In article <-8SdnVrXGqie25jNnZ2dnUVZ7qKdnZ2d at bt.com>,
 Lipska the Kat <lipska at lipskathekat.com> wrote:

> I'm not used to using variables without declaring their type 

If you truly wanted to recreate this type-bondage style of programming 
in Python, it's easy enough to do.

Where you would write in C++:

// Type matching will get checked at compile-time
void my_function(MassivelyParallelFrobinator& mpf, OtherThing& ot) {
   blah, blah, blah

you could write in Python:

# Type matching will get checked at run-time
def my_function(mpf, ot):
   assert isinstance(mpf, MassivelyParallelFrobinator)
   assert isinstance(ot, OtherThing)

but that's just not the way people write code in Python.

More information about the Python-list mailing list