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 @   papering  阅读(9)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 上周热点回顾(2.24-3.2)
历史上的今天:
2022-08-12 6.6 Scheduling and Policing Mechanisms
2022-08-12 Shopee 视频处理技术后台应用
2022-08-12 从汇编分析程序返回值错误的原因
2022-08-12 有哪些代码看上去不一样,其实编译器优化后相同
2022-08-12 二进制位统计算法swar
2022-08-12 Buffer-Overflow Attacks
2021-08-12 t
点击右上角即可分享
微信分享提示