Python字串字母大小寫變換

2021-10-14 20:28:17 字數 592 閱讀 5173

說明:

接下來簡單說明下關於字串大小寫的變換。

操作:

這幾個方法都是生成新的字串,不對原字串內容進行修改。

'''

'''demo =

'this is a good book.'

print

(demo.casefold())

print

(demo.lower())

print

(demo.upper())

print

(demo.capitalize())

print

(demo.title())

print

(demo.swapcase(

))

輸出:

this is a good book.

this is a good book.

this is a good book.

this is a good book.

this is a good book.

this is a good book.

Python 字串字母大小寫轉換

1 str.lower 返回小寫字串 對原字串沒有改變,而是直接返回乙個新的字串 s zxf s1 s.lower print s zxf print s1 zxf 2 str.upper 返回大寫字串 s zxf print s.upper zxf 3 str.capitalize 將首字母變大寫...

Python 字串各種字母大小寫轉換

1 str.lower 返回小寫字串 對原字串沒有改變,而是直接返回乙個新的字串 s zxf s1 s.lower print s zxf print s1 zxf 2 str.upper 返回大寫字串 s zxf print s.upper zxf 3 str.capitalize 將首字母變大寫...

字串整體大小寫轉換,首字母大小寫

最近用到了首字母大寫的功能,一般的思路是採用charat 0 結合character的touppercase方法轉換,最後再拼成乙個字串的方式來實現 日前看到乙個大神的 覺得效率比較高,有興趣的朋友可以看一下 如下 首字母大寫轉換 param str 源字串,首字母不支援中文 return publ...