python字符串格式化

 

字符串格式化:

  • 字符串.format(值1,值2,…)
    
    str.format(格式化字符串1 ,值1,值2…)
    .format(值,格式化字符串)

     

如何去除字符串中的空格:

s = "   13   6  "
print(len(s))
s1 = s.lstrip(' ') #去除前面的空格
print(len(s1))

s1 = s.strip(' ') #去除前后空格
print(len(s1))


s1 = "  ".isspace() #检查是否是空格
print(s1)

 

结果:
在这里插入图片描述

 

posted @ 2020-01-16 00:25  Tony学长  阅读(145)  评论(0编辑  收藏  举报