does lack of type declarations make Python unsafe?

Irmen de Jong irmen at -NOSPAM-REMOVETHIS-xs4all.nl
Sun Jun 15 23:30:26 CEST 2003


beliavsky at aol.com wrote:
> In Python, you don't declare the type of a variable, so AFAIK there is
> no way for the interpreter to check that you are calling functions
> with variables of the correct type.

Indeed, but then again, it usually doesn't have to :-)

Python is a dynamically typed language.
Python is also a strongly typed language.

Dynamic typing makes for very flexible and future-proof code.
To learn more about this, please read
http://www.razorvine.net/python/PythonLanguageConcepts
and
http://home.att.net/~stephen_ferg/projects/python_java_side-by-side.html#typing


> I have only been programming in Python for a few weeks -- am I right
> to worry?

No, there are thousands of Python programs that run just fine!
Python programmers feal perfectly at ease with Python's dynamic
type system. You just have to learn to understand and
appreciate it.

> Are there techniques to ensure that functions are called with
> appropriate arguments?

You *can* test the types of the arguments yourself, inside
the function. But this is regarded bad practice amongst Python
programmers, for the above mentioned reasons.


--Irmen





More information about the Python-list mailing list