运算符和方法之间的区别 [英] Difference between operators and methods

查看:190
本文介绍了运算符和方法之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

运算符和方法之间是否有实质性区别?

我看到的唯一区别是调用方式,它们还有其他区别吗?

例如在Python串联中,切片,索引被定义为运算符,而upper()replace()strip()等(指的是字符串)则是方法.

解决方案

如果我现在能正确理解问题...

简而言之,一切都是对象的方法.您可以在运算符中的python魔术类方法中找到表达式运算符"方法.

那么,为什么python具有诸如[x:y][x]+-之类的性感"东西?因为这对大多数开发人员来说都是常见的事情,甚至不熟悉开发人员,所以+-等数学函数将引起人们的注意,并且他会知道会发生什么.与索引类似-它是许多语言中的通用语法.

但是没有表达upperreplacestrip方法的特殊方法,因此没有表达式运算符".

所以,表达式运算符"和方法之间有什么区别,我只是说它的外观.

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 example in Python concatenation, slicing, indexing are defined as operators, while (referring to strings) upper(), replace(), strip() and so on are methods.

解决方案

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.

这篇关于运算符和方法之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆