not safe at all

James_Althoff at James_Althoff at
Fri Jul 13 16:24:37 EDT 2001

Dennis Roark wrote:
>For amusement, run this little script which demonstrates a
>near ultimate in the lack of type safety in the language.
>(Perhaps there is a bit of type safety in that you can't do
>this:  4 + "one") But look at what you can do in the
>following script:
>x = 3
>x = x + 2
>print "x =", x
>x = "now I'm a string"
>print x
>x = [ 5, x ]
>print "and now a list:", x
>If you don't believe it, run it.  Should any language allow
>x to be such a chameleon, to where it can even be a
>different type on two sides of an assignment?


Each value is a perfectly good object, so why not? (The variable "x"
references an "object" :-).

Side note: see what a Java compiler allows you to put into a collection and
then consider the same issue.


>Dennis Roark
>Dept. of Computer Science
>University of Sioux Falls

More information about the Python-list mailing list