Inconsistent reaction to extend
Bruno Desthuilliers
bdesth.quelquechose at free.quelquepart.fr
Mon Sep 12 18:00:35 EDT 2005
Jerzy Karczmarczuk a écrit :
> Gurus,
No guru answered, so you'll have to bear with me...
> before I am tempted to signal this as a bug, perhaps
> you might convince me that it should be so. If I type
>
> l=range(4)
> l.extend([1,2])
>
> l gives [0,1,2,3,1,2], what else...
>
> On the other hand, try
>
> p=range(4).extend([1,2])
> Then, p HAS NO VALUE (NoneType).
But it does have a value : None. And no need to shout, we here you
pretty well.
Two questions :
1/ Do you *really* think that, *if* it was a bug, no-one would have
noticed ? Seriously ?
2/ Did you Read The Fine Manual(tm) ?
>
> WHY?
BECAUSE!
'destructive' methods like append, extend, sort etc return None, so you
cannot use'em without knowing they are destructive. Rationale is that it
helps the non-programmers avoiding shooting themselves in the foot. I
personnaly find it's a PITA, but what, you'll have to live with it, or
use another language - I, personnaly, choosed to live with it.
BTW, what's wrong with:
p = range(4) + [1, 2]
More information about the Python-list
mailing list