Searching Strings for Specific Endings/Beginnings
The endswith(suffix, [, start, [,end]]) and startswith(prefix, [, start, [,end]]) methods provide a simple and safe way to determine whether a string begins or ends with a specific prefix or suffix, respectively. The first argument is a string used to compare to the prefix or suffix of the string. The endswith and startswith methods are dynamic enough for you to limit the search to within a specific range of the string using the start and/or end arguments. Note The endswith and startswith methods are extremely useful when parsing file lists for extensions or filenames. import os end_str.py Python file: comp_str.py Output from end_str.py code |
Friday, October 23, 2009
Searching Strings for Specific Endings/Beginnings
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment