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 groupby 函数 as_index详解

在官方网站中对as_index有以下介绍: as_index : boolean, default True For aggregated output, return object w...

Python Matplotlib库安装与基本作图示例

Python Matplotlib库安装与基本作图示例

本文实例讲述了Python Matplotlib库安装与基本作图。分享给大家供大家参考,具体如下: 不论是数据挖掘还是数据建模,都免不了数据可视化的问题。对于Python来说,Matpl...

Python get获取页面cookie代码实例

在Python中通过GET来获取页面的COOKIE是非常简单的事情,下面的代码实例演示了如何利用Python 获取COOKIE内容 #! /usr/bin/env python #c...

python实现保存网页到本地示例

学习python示例:实现保存网页到本地复制代码 代码如下:#coding=utf-8__auther__ = 'xianbao'import urllibimport osdef re...

Python3日期与时间戳转换的几种方法详解

日期和时间的相互转换可以利用Python内置模块 time 和 datetime 完成,且有多种方法供我们选择,当然转换时我们可以直接利用当前时间或指定的字符串格式的时间格式。 获取当前...