hti 发表于 2018-8-14 09:06:10

python之字符串操作方法

print(a.center(30,'-'))                         #两侧填充至指定字符  
print(a.rjust(30,'-'))                        #左侧填充至指定字符
  
print(a.ljust(30,'-'))                        #右侧填充至指定字符
  
print(a.encode('utf-8'))                        #使用指定编码集编码
  
print(a.replace('a','i',2))                     #查找指定字符更新替换,更新指定个数a为旧的,i为新的。替换2个
  
print(a.swapcase())                           #大小写交换。小写变大写。大写变小写
  
print(a.capitalize())                           #首字符大写
  
print(a.title())                              #单词首字母大写
  
print(a.lower())                              #字符串中字符全小写
  
print(a.upper())                              #字符串中字符全大写
  
print(a.expandtabs(4))                        #指定制表符长度,默认为8个字节。
页: [1]
查看完整版本: python之字符串操作方法