[Tutor] Why begin a function name with an underscore
eryksun
eryksun at gmail.com
Thu Aug 30 11:23:09 CEST 2012
On Thu, Aug 30, 2012 at 4:44 AM, Peter Otten <__peter__ at web.de> wrote:
>
>>>> sum(["a", "b", "c"], "")
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> TypeError: sum() can't sum strings [use ''.join(seq) instead]
>
> gives me the creeps even though it'd never occur to me to actually use sum()
> to join a sequence of strings.
class Start(object):
def __add__(self, other):
return other
>>> sum(['Bypassing', ' nanny', ' typecheck...'], Start())
'Bypassing nanny typecheck...'
FTFY
(It goes without saying: never do this.)
More information about the Tutor
mailing list