learnpython.org - an online interactive Python tutorial

harrismh777 harrismh777 at charter.net
Mon Apr 25 02:20:46 EDT 2011

Steven D'Aprano wrote:
> It seems to me that weak typing is a Do What I Mean function, and DWIM is
> a notoriously bad anti-pattern that causes far more trouble than it is
> worth. I'm even a little suspicious of numeric coercions between integer
> and float. (But only a little.)

I'm wondering about that as well... (a little)... I mean, maybe the way 
to be really consistent (especially with the Zen of Python, explicit is 
better than implicit) that int --> float --> complex (imaginary) should 
not occur either !

I think folks would baulk at that though... big-time.   :)

So, bottom line here... if my students want to get numbers into their 
programs in 3.x then the correct way to handle the imput() would be:

     n = int(input("enter num > "))

     ... and then let the interpreter throw an exception if the input 
cannot be type cast to int?

kind regards,
m harris

More information about the Python-list mailing list