strip 删除的是字符而不是 字符串

s = 'abcaabc'
s = s.rstrip('abc')


 

#!/usr/bin/python
# -*- coding: UTF-8 -*-

random_string = 'this is good '

# 字符串末尾的空格会被删除
print(random_string.rstrip())

# 'si oo' 不是尾随字符,因此不会删除任何内容
print(random_string.rstrip('si oo'))

# 在 'sid oo' 中 'd oo' 是尾随字符,'ood' 从字符串中删除
print(random_string.rstrip('sid oo'))

# 'm/' 是尾随字符,没有找到 '.' 号的尾随字符, 'm/' 从字符串中删除
website = 'www.runoob.com/'
print(website.rstrip('m/.'))


# 移除逗号(,)、点号(.)、字母 s、q 或 w,这几个都是尾随字符
txt = "banana,,,,,ssqqqww....."
x = txt.rstrip(",.qsw")
print(x)
# 删除尾随字符 *
str = "*****this is string example....wow!!!*****"
print (str.rstrip('*'))
print(x)

Python rstrip()方法 | 菜鸟教程 https://www.runoob.com/python/att-string-rstrip.html

posted @ 2024-08-12 14:22  papering  阅读(5)  评论(0编辑  收藏  举报