String.capwords () function
String.capwords () function, there is a need for friends can refer to the next.
Code:
Import syssys.path.append ("C:/python27/lib") from string import *s= ' AAa dwef sldfji ' Print capwords (s)
Output:
Aaa dwef Sldfji
The function of the capwords () function in the string module: 1. Place the first letter of each word in uppercase 2. Place each word except the first letter in lowercase; 3. Use a space instead of 4 for multiple spaces between words. It has two parameters, the second parameter is used to determine the delimiter between words, the default is a space.
function prototypes (source code interpretation):
# capitalize the words in a string, e.g, "abc def", "ABC def".
def capwords (S, sep=none): "" "Capwords (S [, Sep]), string Split the argument into words using Split, capitalize each W The Ord using capitalize, and join the capitalized words using join. If the optional Second argument Sep is absent or None, runs of whitespace characters be replaced by a single space and Le Ading and trailing whitespace are removed, otherwise Sep was used to split and join the words. "" "Return (Sep or"). Join (X.capitalize () for x in S.split (Sep))
String.capwords () function