a = 'strABC' # Strabc : 首字母大寫,其他全部小寫 b = a.capitalize() print(b) # STRABC : 全部大寫 c = a.upper() print(c) # strabc : 全部小寫 d = a.lower() print(d) # STRabc 大小寫翻轉 e = a.swapcase() print(e) # Abc Edf_Ghi*Jkl.Mno,Pqr,Stu(Vw)Xy4Z 以非英文字母隔開的首字母大寫 a = "abc edf_ghi*jkl.mno,pqr,stu(vw)xy4z" b = a.title() print(b) # #######python####### (寬度,填充物(默認空格)) 字符居中 str = "python" str1 = str.center(20,"#") print(str1) # abc def # a def 當字符串中出現tab時,用空格補充滿tab 8位的倍數,使得后續字符對齊 str = "abc\tdef" str1 = "a\tdef" str2 = str.expandtabs() str3 = str1.expandtabs() print(str2) print(str3)
