* str.startwith() is less errorprone that slice comparisons but not as fast.

* Fix minor typos.
This commit is contained in:
Raymond Hettinger 2003-09-27 02:53:59 +00:00
parent 34893b2b2a
commit a37771e3cb
2 changed files with 6 additions and 6 deletions

View File

@ -546,8 +546,8 @@ Programming Recommendations
same API with unicode strings.
- Avoid slicing strings when checking for prefixes or suffixes.
Use startswith() and endswith() instead, since they are faster,
cleaner and less error prone. E.g.:
Use startswith() and endswith() instead, since they are
cleaner and less error prone. For example:
No: if foo[:3] == 'bar':
Yes: if foo.startswith('bar'):

View File

@ -120,14 +120,14 @@ Replace apply() with a Direct Function Call
'''''''''''''''''''''''''''''''''''''''''''
In Python 2.3, apply() was marked for Pending Deprecation because it
was made obsolete by the Python 1.6's introduction of * and ** in
was made obsolete by Python 1.6's introduction of * and ** in
function calls. Using a direct function call was always a little
faster than apply() because it saved the lookup for the builtin.
Now, apply() is even slower due to its use of the warnings module.
Pattern::
apply(f,args, kwds) --> f(*args, **kwds)
apply(f, args, kwds) --> f(*args, **kwds)
Python 2.2 or Later
@ -277,8 +277,8 @@ Locating: ``grep string *.py | grep import``
``startswith`` and ``endswith`` String Methods
''''''''''''''''''''''''''''''''''''''''''''''
Use these string methods instead of slicing. They're faster because
no slice has to be created, and there's no risk of miscounting.
Use these string methods instead of slicing. No slice has to be
created and there's no risk of miscounting.
Pattern::