• 技术文章 >常见问题 >Python常见问题

    python字符串不要最后字符怎么做?

    yangyang2020-05-07 11:00:40原创2134

    python中可以使用rstrip()方法删除 string 字符串末尾的指定字符(默认为空格)。

    rstrip()方法语法:str.rstrip([chars])

    chars -- 指定删除的字符(默认为空格)

    返回值:返回删除 string 字符串末尾的指定字符后生成的新字符串。

    示例:

    #!/usr/bin/python3
     
    S = "     this is string example....wow!!!     "
    print (S.rstrip())
    S = "*****this is string example....wow!!!*****"
    print (S.rstrip('*'))

    输出结果如下:

    this is string example....wow!!!

    *****this is string example....wow!!!

    更多Python知识请关注Python视频教程栏目。

    专题推荐:python
    品易云
    上一篇:python字符串如何判空? 下一篇:python字典打印乱码怎么解决

    相关文章推荐

    • win10如何安装python模块• python如何控制内存• python中的frame是什么意思?• 如何保存python程序所生产的数据?

    全部评论我要评论

    © 2021 Python学习网 苏ICP备2021003149号-1

  • 取消发布评论
  • 

    Python学习网