Am 21.04.2011 09:19, schrieb Chris Angelico: > On Thu, Apr 21, 2011 at 5:10 PM, Algis Kabaila <akaba...@pcug.org.au> wrote: >> False: Python IS strongly typed, without doubt (though the >> variables are not explicitly declared.) > > Strongly duck-typed though. If I create a class that has all the right > members, it can simultaneously be a file, an iterable, a database, and > probably even a web browser if it feels like it. Is that strong typing > or not?
Yes, that's strong typing, because your class only works in those contexts that you "explicitly" allow it to work in (through implementing an interface, be it an iterator, a file, etc.), independent of "duck-typing" (which is pretty much described by the term interface-based typing IMHO). The difference between strong typing and weak typing is best described by: Python 2.6.5 (r265:79063, Jun 12 2010, 17:07:01) [GCC 4.3.4 20090804 (release) 1] on cygwin Type "help", "copyright", "credits" or "license" for more information. >>> 1+'2' Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: unsupported operand type(s) for +: 'int' and 'str' >>> which means that the interface for implementing "+" on the input types "int" and "str" isn't implemented (i.e., TypeError). Weakly typed languages allow this to work: modelnine@gj-celle ~ $ php <?php echo 1+'2'; ?> 3 modelnine@gj-celle ~ $ through all kinds of type-casting magic, which isn't explicitly specified as interfaces on the objects (PHP also has integer and string objects) themselves. -- --- Heiko. -- http://mail.python.org/mailman/listinfo/python-list