首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往
您找到你想要的搜索结果了吗?
是的
没有找到

python strip() lstrip() rstrip() 使用方法

Python中的strip用于去除字符串的首尾字符串,同理,lstrip用于去除最左边的字符,rstrip用于去除最右边的字符。 这三个函数都可传入一个参数,指定要去除的首尾字符。...需要注意的是,传入的是一个字符数组,编译器去除两端所有相应的字符,直到没有匹配的字符,比如: theString = 'saaaay yes no yaaaass' print theString.strip...theString = 'saaaay yes no yaaaass' print theString.strip('say') print theString.strip('say ') #say...(s) 'hello world' string.strip(s)剔除字符串s左右空格 >>> string.lstrip(s) 'hello world ' >>> string.rstrip(s)...例如 : >>>a='123abc' >>>a.strip('21') '3abc'                                  结果都是一样的 >>>a.strip('12')

1.9K40
领券