On 4/25/2011 2:20 AM, harrismh777 wrote:
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. :)

Guido regards the number classes as subtypes of abstract number.
Given a==d, and b==e, he believes that after
c = a op b
f = d op e
then c == f should be true (in so far as possible).
This is why he wanted to change int division.

In other words, he wants Python math to pretty much imitate calculators,
on the basis that this is what most users expect and want.

This goes along with Python's general polymorphism/genericity/duck-typing philosophy. It is no different from the fact that one can write generic algorithms that give equivalent answers for equivalent inputs of ordered collections or indexable sequences.

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 > "))

Yes.

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

Converted (not cast) to int or float or complex or anything else other than strl.

--
Terry Jan Reedy

--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to