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)
原文:https://www.cnblogs.com/aiworld/p/11612772.html