rstrip()方法

rstrip()方法

描述

rstrip()  方法用于删除字符串尾部指定的字符,默认字符为所有空字符,包括空格、换行(\n)、制表符(\t)等

语法

rstrip()方法语法:

str.rstrip([chars])

参数

  • chars -- 可选参数,要删除的指定字符,默认字符为所有空字符,包括空格、换行(\n)、制表符(\t)等。

返回值

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

实例

以下实例展示了rstrip()函数的使用方法:

str = "     this is string example....wow!!!     "
print(str.rstrip())  #     this is string example....wow!!!

str = "*****this is string example....wow!!!*****"
print(str.rstrip('*')) # *****this is string example....wow!!!

猜你喜欢

转载自www.cnblogs.com/xiaohei001/p/10163061.html