* str.startwith() is less errorprone that slice comparisons but not as fast.
* Fix minor typos.
This commit is contained in:
parent
34893b2b2a
commit
a37771e3cb
|
@ -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'):
|
||||
|
|
|
@ -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::
|
||||
|
||||
|
|
Loading…
Reference in New Issue