問題描述python3環境中。使用strip() 方法遇到的問題為什么會切割錯誤>>> s = "http://img.17dm.com/juren/manhua/1/1.jpg">>> s.lstrip("http://img.17dm.com/juren/manhua/")''>>> s.lstrip("http://img.17dm.com/juren/")'anhua/1/1.jpg'>>> s.lstrip("http://img.17dm.com/")'juren/manhua/1/1.jpg'>>> s.lstrip("http://img.17dm.com/").lstrip("juren/manhua")'1/1.jpg'
1 回答

長風秋雁
TA貢獻1757條經驗 獲得超7個贊
lstrip用法如下:str. lstrip([chars])
lstrip會刪除你后面出現的所有可能的字符串,知道字符串不存在那個列表里。
比方說,str.lstrip('say')
str依次被去除首尾在['s','a','y']數組內的字符,直到字符在不數組內
下面是具體的樣例:
>>> ' spacious '.lstrip()'spacious '>>> "AABAA".lstrip("A")'BAA'>>> "ABBA".lstrip("AB") # both AB and BA are stripped''>>> "ABCABBA".rstrip("AB")'ABC'>>> "ABCABBA".lstrip("AB")'CABBA'
添加回答
舉報
0/150
提交
取消