python字符串去除空格

  1. strip()方法
    str1 = “a b c”
    str1.strip()
  2. replace()方法
    replace(old, new, count)
    str2 = ‘a b c’
    str2.replace(" ", “”)
  3. join()和split()方法
    str3 = ‘a b c’
    str4 = str3.split() #str4 [‘a’, ‘b’, ‘c’]
    str5 = “”.join(str4) # str5 “abc”
全部评论

相关推荐

点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务