Speed of string += string

Greg Ewing (using news.cis.dfn.de) ckea25d02 at sneakemail.com
Mon Apr 14 08:22:39 CEST 2003

achrist at easystreet.com wrote:
> Now, which is preferred:
> 	if astring == "":
> or 
> 	if len(astring) == 0:

The first ought to be faster, since it avoids a
global name lookup and a Python function call,
both of which are fairly expensive.

But better still would be simply

   if astring:

Greg Ewing, Computer Science Dept,
University of Canterbury,	
Christchurch, New Zealand

More information about the Python-list mailing list