python 字符串类方法总结

1.capitalize(self)->str :首字母大写
2.
casefold(self) ->str:将字符串变小写
3.center(self, width, fillchar=None)->str:依据指定width,居中显示字符串,填充字符默认是空格
4.count(self, sub, start=None, end=None)->int:统计子串的个数
5.encode(self, encoding='utf-8', errors='strict')-> bytes:字符串编码
6.endswith(self, suffix, start=None, end=None)-> bool:是否以suffix结尾
7.expandtabs(self, tabsize=8)->str:用\t补齐不足位数,用于格式化输出  
#for example:
test='username\tpassword\ntest\t1111\n' v=test.expandtabs(20)
print(v)
#结果如下:

猜你喜欢

转载自www.cnblogs.com/itrain/p/9020530.html