[Edu-sig] Consistency question

Kirby Urner urnerk at qwest.net
Wed Sep 24 20:02:40 EDT 2003



My understanding is that int(5.0) actually triggers __int__ -- a method
inherited by all floats.  

When I go dir(5.0), I see __int__ listed, and I can go:

 >>> 5.0 .__int__()
 5

So far so good.  

But then I can also go int('123') and get back 123.  So why isn't __int__ a
method of string objects?

 >>> '123' .__int__()

gets me an error, and dir('') doesn't show __int__ as being among string's
methods.

Why?

I'd like to clear up this confusion because I'm writing some tutorial
materials.  What I don't understand, I can't rightly explain.

Kirby





More information about the Edu-sig mailing list