Why does Python use 'magic methods'?

后端 未结 7 1656
既然无缘
既然无缘 2020-11-29 16:56

I\'ve been playing around with Python recently, and one thing I\'m finding a bit odd is the extensive use of \'magic methods\', e.g. to make its length available, an object

7条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-29 17:54

    They are not really "magic names". It's just the interface an object has to implement to provide a given service. In this sense, they are not more magic than any predefined interface definition you have to reimplement.

提交回复
热议问题