sum and strings

Paul Rubin http
Fri Aug 25 10:47:10 EDT 2006


Bryan Olson <fakeaddress at nowhere.org> writes:
> And herein is the problem: A class may implement "__add__" any
> way the programmer chooses. Python should require, or at least
> document requirements, on further properties of addition. Python
> should insist that addition be symmetric an transitive, and
> classes implementing addition provide an additive identity.

Are you saying "abc"+"def" should not be concatenation?  I guess
that's reasonable.  As long as + is string concatenation though, the
principle of least astonishment suggests that "sum" should
conconcatenate several strings.

I'm not sure what you mean by addition being symmetric or transitive;
it is not an equivalence relation.  Do you mean commutative and
associative?  I'm not sure if floating-point arithmetic has those
properties, strictly speaking.



More information about the Python-list mailing list