sum and strings
Paul Rubin
http
Thu Aug 24 18:44:58 EDT 2006
Fredrik Lundh <fredrik at pythonware.com> writes:
> "join" doesn't use __add__ at all, so I'm not sure in what sense that
> would be more predictable. I'm probably missing something, but I
> cannot think of any core method that uses a radically different
> algorithm based on the *type* of one argument.
3 ** 2, vs. 3 ** 2.5
Actually it's worse than depending on just the type:
(-3.0) ** 2.0 works, while (-3.0) ** 2.5 throws an error.
But you can do
(-3.0) ** (2.5 + 0.0j)
for yet another radically different algorithm.
I'm not sure whether the Python spec requires (-3.0)**2.0 to work, or
if it's just an implementation-specific hack. In most languages, it
wouldn't work.
More information about the Python-list
mailing list