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

Barry A. Warsaw barry@zope.com
Sun, 2 Dec 2001 19:27:54 -0500


>>>>> "TP" == Tim Peters <tim@zope.com> writes:

    TP> Once you're used to {starts,ends}with() (about the third time
    TP> you use them), they're *always* more readable than slicing.

Yep, and I prefer them to slicing even when testing the first or last
character:

    if somestring.startswith('^'):
	# do caret

    if somestring.endswith('\n'):
	# don't add it

-Barry