Reply to comment

Python Operator Overloading

I was reading up on Django F() and Q(). I didn't know Python had operator overloading. They call it magic methods.

Magic Methods on Rafe Kettler

There's a pretty good tutorial at Treehouse.

But... a few memories of arguments about operator overloading surfaced, so I had to think about why Java rejected adding the feature to Java.

Oh yeah, here's a good overview of right and wrong ways to use and abuse operators.

It looks like Python's doing it by treating operators like syntactic sugar to dispatch magic methods. Good. Infix-to-s-expressions is a good thing.

Reply

The content of this field is kept private and will not be shown publicly.
  • Lines and paragraphs break automatically.

More information about formatting options

1 + 4 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.