Is Python type safe?

Roy Smith roy at
Tue Mar 16 20:18:39 CET 2004

In article <221d8dbe.0403161043.52406195 at>,
 srijit at wrote:

> Hello,
> I would like to know the definition of type safe and whether Python
> can be considered as a type safe language. Similarly are Java, C# or
> C++ type safe?
> Regards,
> Srijit

You tell me what you mean by "type safe", and I'll tell you if those 
languages meet that definition.

C++ and Java both have the concept of declaring variables to hold a 
certain type of data.  I don't know anything about C#, but I'll assume I 
can lump it into the C++/Java camp.

Python on the other hand, carries the type information along with the 
data, not with the variable (container) that holds the data.

Neither C++ nor Python will let you add the integer 3 to the string 
"four", but use different mechanisms to prevent it.  Oddly enough, Java 
(in a perl-like, but admittedly convenient, stab at automagic 
polymorphism) will let you add them.  No clue what C# does.

Which is type safe and which isn't?  Well, I think we're back to my 
first statement, otherwise we quickly get into playing three blind men 
and the elephant.

More information about the Python-list mailing list