Why does str not have a __radd__ method?

Steven D'Aprano steve+comp.lang.python at pearwood.info
Wed Aug 13 13:55:46 EDT 2014


Ethan Furman wrote:

> On 08/13/2014 09:00 AM, Steven D'Aprano wrote:
>>
>> What is the rationale for str not having __radd__ method?
> 
> At a guess I would say because string only knows how to add itself to
> other strings, so __add__ is sufficient.

# Python 2.7
py> "Hello" + u"World"
u'HelloWorld'
py> unicode.__radd__
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: type object 'unicode' has no attribute '__radd__'


My brain hurts.



-- 
Steven




More information about the Python-list mailing list