Python rstrip()方法实例详解

yipeiwu_com5年前Python基础

Python 字符串

描述

Python rstrip() 删除 string 字符串末尾的指定字符(默认为空格).

语法

rstrip()方法语法:

str.rstrip([chars])

参数

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

返回值

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

实例

以下实例展示了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 rstrip()方法实例详解,希望对大家有所帮助,如果大家有任何疑问欢迎给我留言,小编会及时回复大家的!

相关文章

python局部赋值的规则

复制代码 代码如下:  myVar = 1 def myfunc():    myVar += 1 myfunc()    &...

详解python之heapq模块及排序操作

说到排序,很多人可能第一想到的就是sorted,但是你可能不知道python中其实还有还就中方法哟,并且好多种场景下效率都会比sorted高。那么接下来我就依次来介绍我所知道的排序操作。...

python开发中range()函数用法实例分析

本文实例讲述了python开发中range()函数用法。分享给大家供大家参考,具体如下: python中的range()函数的功能很强大,所以我觉得很有必要和大家分享一下 就好像其API...

matplotlib subplots 设置总图的标题方法

如下所示: matplotlib subplots 设置总图的标题 : fig.suptitle(dname,fontsize=16,x=0.53,y=1.05,) 以上这篇matplo...

pytorch中的自定义反向传播,求导实例

pytorch中自定义backward()函数。在图像处理过程中,我们有时候会使用自己定义的算法处理图像,这些算法多是基于numpy或者scipy等包。 那么如何将自定义算法的梯度加入到...