not safe at all

James_Althoff at i2.com James_Althoff at i2.com
Fri Jul 13 22:24:37 CEST 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?

Absolutely!!!

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.

Jim


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





More information about the Python-list mailing list