On Mon, 9 Mar 2015 15:12:44 +1100 Steven D'Aprano <st...@pearwood.info> wrote: > > My summary is as follows: > > __int__ is used as the special method for int(), and it should coerce > the object to an integer. This may be lossy e.g. int(2.999) --> 2 or may > involve a conversion from a non-numeric type to integer e.g. int("2").
Your example is misleading. Strings don't have an __int__: >>> s = "3" >>> s.__int__() Traceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: 'str' object has no attribute '__int__' Only int-compatible or int-coercible types (e.g. float, Decimal) should have an __int__ method. Regards Antoine. _______________________________________________ Python-Dev mailing list Python-Dev@python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com