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

相关文章

pymysql的简单封装代码实例

这篇文章主要介绍了pymysql的简单封装代码实例,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下 #coding=utf-8 #...

Python内置的字符串处理函数整理

str='python String function' 生成字符串变量str='python String function'字符串长度获取:len(str)例:print '%s l...

tensorflow获取变量维度信息

tensorflow版本1.4 获取变量维度是一个使用频繁的操作,在tensorflow中获取变量维度主要用到的操作有以下三种: Tensor.shape Tensor.get...

浅谈django orm 优化

orm优化 1.数据库技术进行优化,包括给字段加索引,设置唯一性约束等等; 2.查询过滤工作在数据库语句中做,不要放在代码中完成(看情况); 3.如果要一次查询出集合的数量,使用c...

对Python正则匹配IP、Url、Mail的方法详解

如下所示: """ Created on Thu Nov 10 14:07:36 2016 @author: qianzhewoniuqusanbu """ import re...