diff options
author | Ezio Melotti <ezio.melotti@gmail.com> | 2009-09-26 12:33:22 (GMT) |
---|---|---|
committer | Ezio Melotti <ezio.melotti@gmail.com> | 2009-09-26 12:33:22 (GMT) |
commit | a40bdda9377dfaa9a39a4019cecbe16e3ca9f884 (patch) | |
tree | df5947b2a54fefb0a6f5ee82c1ff824651091e86 /Lib/string.py | |
parent | 2c6a949e43f55ddd0a09e1eba611f03a47268913 (diff) | |
download | cpython-a40bdda9377dfaa9a39a4019cecbe16e3ca9f884.zip cpython-a40bdda9377dfaa9a39a4019cecbe16e3ca9f884.tar.gz cpython-a40bdda9377dfaa9a39a4019cecbe16e3ca9f884.tar.bz2 |
Merged revisions 75070 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r75070 | ezio.melotti | 2009-09-26 14:20:53 +0300 (Sat, 26 Sep 2009) | 1 line
#7000: document "sep" in capwords. Add a few tests
........
Diffstat (limited to 'Lib/string.py')
-rw-r--r-- | Lib/string.py | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/Lib/string.py b/Lib/string.py index 4599997..5089193 100644 --- a/Lib/string.py +++ b/Lib/string.py @@ -29,15 +29,17 @@ printable = digits + ascii_letters + punctuation + whitespace # Capitalize the words in a string, e.g. " aBc dEf " -> "Abc Def". def capwords(s, sep=None): - """capwords(s, [sep]) -> string + """capwords(s [,sep]) -> string Split the argument into words using split, capitalize each word using capitalize, and join the capitalized words using - join. Note that this replaces runs of whitespace characters by - a single space. + join. If the optional second argument sep is absent or None, + runs of whitespace characters are replaced by a single space + and leading and trailing whitespace are removed, otherwise + sep is used to split and join the words. """ - return (sep or ' ').join([x.capitalize() for x in s.split(sep)]) + return (sep or ' ').join(x.capitalize() for x in s.split(sep)) #################################################################### |