[Python-ideas] allow `lambda' to be spelled λ
Chris Angelico
rosuav at gmail.com
Wed Jul 13 01:49:13 EDT 2016
On Wed, Jul 13, 2016 at 3:43 PM, Pavol Lisy <pavol.lisy at gmail.com> wrote:
> 3.
> Questions around "only one possibilities how to write it" could be
> probably answered with this?
>
> a<b
> a.__lt__(b)
Those aren't the same, though. One is the interface, the other is the
implementation. Dunder methods are for defining, not for calling.
Also:
rosuav at sikorsky:~$ python3
Python 3.6.0a2+ (default:4ef2404d343e, Jul 11 2016, 12:37:20)
[GCC 5.3.1 20160528] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> class B:
... def __gt__(self, other):
... print("Am I greater than %s?" % other)
... return False
...
>>> a = 5
>>> b = B()
>>> a < b
Am I greater than 5?
False
Operators can have multiple implementations (in this case, the
interpreter found that "int < B" didn't have an implementation, so it
switched it to b > a and re-evaluated).
ChrisA
More information about the Python-ideas
mailing list