开发者社区> 问答> 正文

python中能删除字符串中的空格集中函数具体都有哪些呢?

python中能删除字符串中的空格集中函数具体都有哪些呢?

展开
收起
游客vwuxaq6iqaowc 2021-11-02 18:49:28 508 0
1 条回答
写回答
取消 提交回答
  • c =' hello world !!! ' (1)去掉字符串开头和末尾的空格 print(c.strip()) (2)去掉字符串左边的空格 print(c.lstrip()) (3)去掉字符串右边的空格 print(c.rstrip()) (4)去掉字符串中所有的空格 print(c.replace(' ','')) 输出依次为: hello world !!! hello world !!! hello world !!! helloworld!!! 注意:这里不要把strip函数和split函数搞混了,前者是删除字符串中指定的字符,默认为空格,后者是用指定的字符分割字符串,默认也是空格

    2021-11-02 18:49:52
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
From Python Scikit-Learn to Sc 立即下载
Data Pre-Processing in Python: 立即下载
双剑合璧-Python和大数据计算平台的结合 立即下载