String.capwords () function

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.