Keyboard input A word in English, capitalize the first letter of each word

Source: Internet
Author: User
Tags lowercase ord

In Python, there is code that can implement this function directly

str2 = "Hello nice to meet
Print (Str2.title ())
There are a couple of similar features
Convert #将字符串中的大写转化成小写 lowercase to uppercase
print (Str2.swapcase ())

#就第一个首字母大写 Other lowercase
print (str2.capitalize ())

Use your own method to capitalize the first letter of each word:

def Huan (src):
    str1= ';
    Len1=len (SRC);
    For I in Range (LEN1):
        if (i==0):
            str1=chr (Ord (src[i)) -32);
            Print (str1,end= ');
        Elif (src[i-1]== '):
            str1=chr (Ord (src[i)) -32);
            Print (str1,end= ');
        else:
             Str1=src[i];
             Print (str1,end= ');
Num1=input (' Input string: ');
Huan (NUM1);
Method Two:
Str1=input (' Input string: ');
List1=str1.split ();
For sub in List1:
    sub1=sub.replace (SUB[0],CHR (Ord (sub[0)) -32);
    Print (sub1,end= ');


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.