Can bin() be overloaded like oct() and hex() in Python 2.6?

后端 未结 4 528
旧时难觅i
旧时难觅i 2021-02-05 12:26

In Python 2.6 (and earlier) the hex() and oct() built-in functions can be overloaded in a class by defining __hex__ and __oct__

4条回答
  •  萌比男神i
    2021-02-05 13:29

    The bin function receives it's value from the object's __index__ function. So for an object, you can define the value converted to binary, but you can't define the format of the string.

提交回复
热议问题