List append vs add
Thomas Wouters
thomas at xs4all.net
Fri May 25 05:58:18 EDT 2001
On Fri, May 25, 2001 at 08:45:47AM +0100, Michael Hudson wrote:
> Tim Howarth <tim at worthy.demon.co.uk> writes:
> > Is there any difference in result, performance or stylistic approval
> > ('niceness') of;
> >
> > list.append('fred')
> >
> > compared with,
> >
> > list+=['fred']
> There is no difference in result. The former strikes me as clearer,
> and might well be quicker.
It is quicker, but not by much. The += version skips the method lookup,
method call, and argument parsing that the .append version has to go
through, at the cost of a function-lookup in the type slot. The real work is
done in the same function in both cases, though, so you won't really notice
the difference.
--
Thomas Wouters <thomas at xs4all.net>
Hi! I'm a .signature virus! copy me into your .signature file to help me spread!
More information about the Python-list
mailing list