learnpython.org - an online interactive Python tutorial
harrismh777 at charter.net
Thu Apr 21 09:29:00 CEST 2011
Algis Kabaila wrote:
> Python is completely object oriented, and not "strongly typed"
> False: Python IS strongly typed, without doubt (though the
> variables are not explicitly declared.)
Playing the advocate for a moment here, this is something that I was
confused about early on also... and frankly, you are both correct, but
from different vantage points.
Python IS strongly typed in that operations may only be applied to
objects that support 'that' operation... numbers support (+) and also
strings support (+) , although, the (+) does 'different' things
depending on the object type. You might look at this as STRONGLY typed
and you would be correct... however, you might look on this as weakly
typed and you would still be correct... because why?
Because, the programmer doesn't have to worry about the 'types' she is
using ... the object based nature of the language and polymorphism come
together so that the 'right thing' happens with (+) regardless of
type... see? weakly typed...
In C the programmer is always considering what 'type' is this thing...
even testing for it... and C is considered by those programmers (yes, me
) as STRONGLY typed. The types must be declared ahead of time for sure,
but that's not the point... the point is that the 'type' matters and
must always be on the front lobes in thinking about logic.
In Python much of the thinking about types is not even necessary.. for
the most part... and by design. In this way of thinking the language is
weakly typed... on the other hand, because the objects may be only
manipulated by operations they support, this makes Python STRONGLY
typed. Confused yet???
How one thinks about this depends on programming background, what is
meant by 'type' and how the programmer differentiates thinking about
types as variables versus objects.
Having said all of that, I agree that Python should be classified as
STRONGLY typed... and this classification should always come with an
explanation ... especially to new advocates writing tutorials...
More information about the Python-list