1. 程式人生 > >字符串方法title()、istitle()

字符串方法title()、istitle()

語義 true 檢測 tle 方法 檢測字符串 字符串方法 首字母 str

title()、istitle()

語義解釋:

title() 方法返回"標題化"的字符串,就是說所有單詞的首個字母轉化為大寫,其余字母均為小寫。

istitle() 方法檢測字符串中所有的單詞拼寫首字母是否為大寫,且其他字母為小寫。

實際運用:

1 a=b=hello  world!
2 print(a.title())
3 print(a.title().istitle())
4 print(b.istitle())

Hello World!
True
False

字符串方法title()、istitle()