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

yipeiwu_com6年前Python基础

 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实现线程状态监测简单示例

Python实现线程状态监测简单示例

本文实例讲述了Python实现线程状态监测。分享给大家供大家参考,具体如下: # -*- coding:utf-8 -*- from threading import Thread...

python清除字符串中间空格的实例讲解

1、使用字符串函数replace >>> a = 'hello world' >>> a.replace(' ', '') 'helloworld...

详解PyCharm配置Anaconda的艰难心路历程

详解PyCharm配置Anaconda的艰难心路历程

在安装好pycharm后,想着anaconda中的类库会比较全,就想着将anaconda配置到pycharm中,这样可以避免以后下载各种类库。 第一步就是要下载并安装anaconda,在...

Django ManyToManyField 跨越中间表查询的方法

1、在 django 表中用到了 manytomany 生成了中间表 pyclub_article_column from django.db import models # Cr...

selenium+python 对输入框的输入处理方法

最近自己在做项目的自动化测试(公司无此要求),在用户管理模块做修改用户信息时,脚本已经跑成功,并且的确做了update操作,但是自己登陆页面检查,信息却没有被修改,再次确定系统该模块的编...