在Python中操作字符串之rstrip()方法的使用

作者:goldensun 时间:2022-03-22 18:34:36 

 rstrip()方法返回所有字符都被去除的字符串(缺省为空格字符)结束字符串的副本。
语法

以下是rstrip()方法的语法:


str.rstrip([chars])

参数

  •     chars -- 可以提供要去除的字符。

返回值

此方法返回的所有字符都被去除的字符串(缺省为空格字符)结束字符串的副本。
例子

下面的例子显示了rstrip()方法的使用。


#!/usr/bin/python

str = "  this is string example....wow!!!  ";
print str.rstrip();
str = "88888888this is string example....wow!!!8888888";
print str.rstrip('8');

当我们运行上面的程序,它会产生以下结果:


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

标签:Python
0
投稿

猜你喜欢

  • Python3爬虫里关于Splash负载均衡配置详解

    2022-11-24 22:54:19
  • 试试把xml和javascript写到同一个文件里面

    2009-10-02 16:53:00
  • go语言优雅地处理error工具及技巧详解

    2023-07-16 18:56:56
  • DWCS3-CSS布局之一CSS规则大纲

    2008-06-11 18:48:00
  • python分布式环境下的限流器的示例

    2023-07-11 19:25:38
  • 可爱动态背景输入框

    2009-05-07 13:50:00
  • 如何让python程序正确高效地并发

    2021-10-14 20:33:54
  • Python编写淘宝秒杀脚本

    2021-01-31 23:23:42
  • python批量读取文件名并写入txt文件中

    2021-02-18 16:32:29
  • pytorch深度神经网络入门准备自己的图片数据

    2023-12-07 13:55:58
  • python中mechanize库的简单使用示例

    2021-05-22 14:32:12
  • Python 3.6 中使用pdfminer解析pdf文件的实现

    2023-09-02 08:34:08
  • 彻底删除thinkphp3.1案例blog标签的方法

    2023-11-21 12:01:01
  • python获取糗百图片代码实例

    2022-09-10 01:44:01
  • 深入认识javascript中的eval函数

    2008-08-03 16:44:00
  • 浅谈python中np.array的shape( ,)与( ,1)的区别

    2022-12-07 21:22:09
  • python 正则表达式的使用

    2022-02-16 15:29:09
  • Python制作exe文件简单流程

    2022-06-07 01:11:12
  • Python如何将图像音视频等资源文件隐藏在代码中(小技巧)

    2023-08-03 10:29:49
  • python实现Pyecharts实现动态地图(Map、Geo)

    2021-01-21 11:33:58
  • asp之家 网络编程 m.aspxhome.com