can I overload operators like "=>", "->" or something like that?

Ben Finney ben+python at benfinney.id.au
Fri Apr 20 02:09:52 EDT 2012


alex23 <wuwei23 at gmail.com> writes:

> On Apr 20, 5:54 am, Jacob MacDonald <jaccar... at gmail.com> wrote:
>
> > On Thursday, April 19, 2012 12:28:50 PM UTC-7, dmitrey wrote:
> > > can I somehow overload operators like "=>", "->" or something like
> > > that?
> > I don't believe that you could overload those particular operators,
> > since to my knowledge they do not exist in Python to begin with.

There is no ‘=>’ operator, and no ‘->’ operator, in Python
<URL:http://docs.python.org/reference/lexical_analysis.html#operators>.
>
> It all depends on if the operators use special methods on objects:
> http://docs.python.org/reference/datamodel.html#special-method-names
>
> You can overload => via object.__le__, for example.

No, ‘<=’ is the less-than-or-equal operator. There is no ‘=>’ operator
in Python.

-- 
 \      “I knew things were changing when my Fraternity Brothers threw |
  `\           a guy out of the house for mocking me because I'm gay.” |
_o__)                                      —postsecret.com, 2010-01-19 |
Ben Finney



More information about the Python-list mailing list