Python字符串rstrip()
方法返回从字符串末尾删除所有字符串的字符串(默认空白字符)的副本。
语法
以下是rstrip()
方法的语法 -
str.rstrip([chars])
参数
- chars - 要修剪的字符。
返回值
- 返回从字符串末尾删除所有字符串的字符串(默认空白字符)的副本。
示例
以下示例显示了rstrip()
方法的用法 -
#!/usr/bin/python3
str = " this is string example....wow!!! "
print (str.rstrip())
str = "*****this is string example....wow!!!*****"
print (str.rstrip('*'))
当运行上面的程序,它产生以下结果 -
this is string example....wow!!!
*****this is string example....wow!!!