字符串大小寫轉換
1、upper()
字符串中所有字符轉成大寫。
2、lower()
字符串中所有字符轉成小寫。
3、swapcase()
字符串中所有字符,大寫轉成小寫,小寫轉成大寫。
4、capitalize()
第一個字符轉成大寫,其余字符轉成小寫。
5、title()
每個單詞第一個字符轉成大寫,其余字符轉成小寫。
1 #字符串的大小寫轉換 2 s = 'hello,python' 3 a = s.upper() # 轉成大寫后會產生新的字符串 4 print(s, id(s)) 5 print(a, id(a)) 6 7 b = s.lower() # 轉成小寫后會產生新的字符串 8 print(s, id(s)) 9 print(b, id(b)) 10 11 s2 = 'hello,Python' 12 print(s2.swapcase()) 13 14 print(s2.title())