Python3 title()方法

Python3 字串 Python3 字串


描述

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

語法

title()方法語法:

str.title();

參數

  • NA。

返回值

返回"標題化"的字串,就是說所有單詞的首字母都轉化為大寫。

實例

以下實例展示了 title()函數的使用方法:

實例(Python 3.0+)

#!/usr/bin/python3 str = "this is string example from zaixian....wow!!!" print (str.title())

以上實例輸出結果如下:

This Is String Example From zaixian....Wow!!!

請注意,非字母後的第一個字母將轉換為大寫字母:

實例(Python 3.0+)

#!/usr/bin/python3 txt = "hello b2b2b2 and 3g3g3g" x = txt.title() print(x)

輸出結果為:

Hello B2B2B2 And 3G3G3G

Python3 字串 Python3 字串