【问题标题】:Are magic methods (dunders) in Python same as operator overloading in C++?Python中的魔术方法(dunders)与C++中的运算符重载相同吗?
【发布时间】:2015-12-04 17:30:20
【问题描述】:

例如,在 Python 中使用 __eq__ 是否与在 C++ 中使用 operator== 相同?魔术方法在 Python 中还有其他功能吗?

【问题讨论】:

  • 有很多dunder方法与运算符重载无关:__str____len____iter____hash__

标签: python c++ operator-overloading magic-methods


【解决方案1】:

是的,不是的。虽然实现/覆盖__eq____div__ 等与其他语言中的运算符重载相同,但某些__ 方法不一定类似于其他语言中的方法。

【讨论】:

    猜你喜欢
    • 2014-01-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-10
    • 1970-01-01
    相关资源
    最近更新 更多