[Zope-Coders] x.startswith() vs. x[ ..]

Shane Hathaway shane@zope.com
Sun, 02 Dec 2001 00:01:07 -0500


Andreas Jung wrote:

> I just made a small benchmark comparing  startwith()/endswith() on strings
> against the corresponding string slicing.  Using string methods is about 30%
> faster
> than slicing and sometimes the code is more readable. Maybe we should keep
> that in mind for performance reasons when working on Zope 2/3.

You're absolutely right, Andreas.  When I moved to Python from Java I 
had to unlearn "<str>.startswith()" since it didn't exist.  Now, a 
couple of years later, I have to reverse my unlearning.  Aside from all 
the mental mutations, startswith() is a good thing all around.  Thanks.

Shane