On 14/10/21 11:19 am, Greg Ewing wrote:
Not really -- __int__ is expected to return something of type int, whereas __trunc__ is expected to return the same type as its operand.
Scratch that, it seems __trunc__ also returns an int, at least for floats. Not sure what the logic behind that is. There are differences between the functions int() and trunc() though: >>> int("42") 42 >>> trunc("42") Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: type str doesn't define __trunc__ method Conceptually, I would say that int() is a type conversion, whereas trunc() is an operation on numbers. A type would be entitled to implement them both but differently. -- Greg _______________________________________________ Python-Dev mailing list -- python-dev@python.org To unsubscribe send an email to python-dev-le...@python.org https://mail.python.org/mailman3/lists/python-dev.python.org/ Message archived at https://mail.python.org/archives/list/python-dev@python.org/message/OM5UB5LRMOSKTVGJWV3G7TP7Z7DNFE2M/ Code of Conduct: http://python.org/psf/codeofconduct/