Slicing vs .startswith

Peter Hansen peter at engcorp.com
Mon Sep 22 14:23:52 EDT 2003


Shu-Hsien Sheu wrote:
> 
> I have a question about the comparison of efficiency of string slicing
> and using string.startswith.
> For example, which one of the following would be more efficient, or ,
> moreover, more pythonic?
> 
> if aa[:3] == 'abc':
> 
> vs
> 
> if aa.startswith('abc'):

The latter is clearly more readable.




More information about the Python-list mailing list