python Python:upper,lower,append,join,split:转换为Titlecase

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python Python:upper,lower,append,join,split:转换为Titlecase相关的知识,希望对你有一定的参考价值。

#!/usr/bin/env python3


def titlecase(s):
    spl, al = s.split(), []

    for i in range(len(spl)):
        al.append(spl[i][0].upper() + spl[i][1:].lower())
    print(' '.join(al))

titlecase('hello world')
titlecase('2hello 3world')
titlecase('#hello &world')

以上是关于python Python:upper,lower,append,join,split:转换为Titlecase的主要内容,如果未能解决你的问题,请参考以下文章

python中的 upper() lower()capitalize()title()方法

python3----转换大小写(upper lower capitalize and title)

Python title()upper()lower()方法--string

python Python:upper,lower,append,join,split:转换为Titlecase

Python小刀 -title()- lower()- upper()- 调整名字大小写

python字符串相关函数 *title *upper *lower *swapcase *len *count *find *index *starts with *endswith