operator module functions

Chris Kaynor ckaynor at zindagigames.com
Thu Oct 9 00:40:18 CEST 2014


On Wed, Oct 8, 2014 at 3:30 PM, Chris Angelico <rosuav at gmail.com> wrote:

> >
> >
> > That doesn't always seem to have been the case, however.
> > In Python 2.7 and 3.3, I get
> >
> >>>> operator.add is operator.__add__
> > False
>
> Huh. So it is.
>
> rosuav at sikorsky:~$ python3
> Python 3.5.0a0 (default:301b9a58021c, Oct  2 2014, 09:20:24)
> [GCC 4.7.2] on linux
> Type "help", "copyright", "credits" or "license" for more information.
> >>> import operator
> >>> operator.add, operator.__add__
> (<built-in function add>, <built-in function add>)
> >>>
> rosuav at sikorsky:~$ python
> Python 2.7.3 (default, Mar 13 2014, 11:03:55)
> [GCC 4.7.2] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
> >>> import operator
> >>> operator.add, operator.__add__
> (<built-in function add>, <built-in function __add__>)
> >>>
>
> Presumably they have the same code behind them, just different
> function names. But anyway, the fact that it doesn't throw back an
> AttributeError proves that both functions do at least exist.
>
> Learn something new every day!


I only tried it in Python 3.4, and I got true. Perhaps it was optimized
slightly after 3.3?

Chris
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20141008/6029c19e/attachment.html>


More information about the Python-list mailing list