Difference between operators and methods

后端 未结 3 412
我寻月下人不归
我寻月下人不归 2021-01-06 07:59

Is there any substantial difference between operators and methods?

The only difference I see is the way the are called, do they have other differences?

For

3条回答
  •  醉梦人生
    2021-01-06 08:38

    If I understand question currectly...

    In nutshell, everything is a method of object. You can find "expression operators" methods in python magic class methods, in the operators.

    So, why python has "sexy" things like [x:y], [x], +, -? Because it is common things to most developers, even to unfamiliar with development people, so math functions like +, - will catch human eye and he will know what happens. Similar with indexing - it is common syntax in many languages.

    But there is no special ways to express upper, replace, strip methods, so there is no "expression operators" for it.

    So, what is different between "expression operators" and methods, I'd say just the way it looks.

提交回复
热议问题