今天跟大家介紹說明Python 字串物件的一個方法 str.title()
Return a titlecased version of the string where words
start with an uppercase character and the remaining
characters are lowercase.
意思是說我們可以透過使用字串str.title()的方法,將字串中每一個字的第一個字母轉成大寫其餘字元為小寫。可見下面程式範例:
strTitle = 'the school have many students.'
# 將輸入每個字第一個字元轉成大寫並印出
# The School Have Many Students.
print(strTitle.title())