[Tutor] Calling a number's methods
Alan Gauld
alan.gauld at btinternet.com
Wed Jun 23 08:47:47 CEST 2010
"Mark Young" <marky1991 at gmail.com> wrote
> I searched the internet, and found someone suggest adding spaces
> after each
> number, which indeed works properly.
>
>>>> answer = 6 .__sub__(7 .__neg__())
>>>> answer
> 13
>
> Why does this work? I don't even understand why python recognizes
> that I'm
> trying to access the numbers' __sub__ and __neg__ methods, I would
> think
> that the spaces would cause it to not work, but obviously it works
> just
> fine.
I assume that's a hard coded hack in python to avoid some ambiguity
with
decimal points. But I'm not sure. And I'd have thought it should be
possible
to disambiguate without the space...
But that's my guess. I've certainly never come across this "feature"
before.
Alan G.
More information about the Tutor
mailing list