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

发布时间:2022-06-20 09:46:06 人气:138 作者:多测师

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

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

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

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

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

  示例:

  #!/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相关知识,请关注多测师。https://www.e70w.com/xwzx/


返回列表
在线客服
联系方式

热线电话

17727591462

上班时间

周一到周五

二维码
线