Python rstrip()方法实例详解

yipeiwu_com6年前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中的异常处理学习笔记

Python 是面向对象的语言,所以程序抛出的异常也是类。 常见的异常类 1.NameError:尝试访问一个没有申明的变量 2.ZeroDivisionError:除数为 0 3.Sy...

python 获取url中的参数列表实例

Python的urlparse有对url的解析,从而获得url中的参数列表 import urlparse urldata = "http://en.wikipedia.org/w/...

搞清楚 Python traceback的具体使用方法

1. Python中的异常栈跟踪 之前在做Java的时候,异常对象默认就包含stacktrace相关的信息,通过异常对象的相关方法printStackTrace()和getStackT...

实例讲解Python的函数闭包使用中应注意的问题

昨天正当我用十成一阳指功力戳键盘、昏天暗地coding的时候,正好被人问了一个问题,差点没收好功,洪荒之力侧漏震伤桌边的人,废话不多说,先上栗子(精简版,只为说明问题): from...

python判断输入日期为第几天的实例

如下所示: # -*- coding: utf-8 -*- # 简述:要求输入某年某月某日 # 提问:求判断输入日期是当年中的第几天? def which_day(year,mont...