(1)capitlize函数(将字符串首字母改为大写)
1 h = ‘doudizhu‘ 2 v = h.capitalize() 3 print(v)
输出为:Doudizhu
(2)lower函数(将字符串中所有字母变小写)
1 h = ‘DouDiZhu‘ 2 v = h.lower() 3 print(v)
输出为:doudizhu
(3)casefold函数(将字符串中所有字母变小写)(推荐)
1 h = ‘DouDiZhu‘ 2 v = h.casefold() 3 print(v)
输出为:doudizhu
(4)center函数(设置字符串宽度为30,并将字符串居中,‘华‘作为填充(只能是一个字符,大于一个字符会报错))
1 h = ‘doudizhu‘ 2 v = h.center(30,‘华‘) 3 print(v)
输出为:华华华华华华华华华华华doudizhu华华华华华华华华华华华
原文:https://www.cnblogs.com/maergaiyun/p/9509426.html