python lstrip()函数

今天看到一小段代码,然后发现一个貌似很常见的api,因为不怎么用,所以查了一下。结果,越查越迷糊

str.lstrip([chars])
Return a copy of the string with leading characters removed. The chars argument is a string specifying the set of characters to be removed. If omitted or None, the chars argument defaults to removing whitespace. The chars argument is not a prefix; rather, all combinations of its values are stripped:

>>>
>>> '   spacious   '.lstrip()
'spacious   '
>>> 'www.example.com'.lstrip('cmowz.')
'example.com'

官网是这样写的。api的解释不可谓不详细,但是再对照下面的例子,直接就迷糊了。

先是谷歌,没发现好的解释,全是千篇一律的转载。然后又百度,终于发现了一个正确的解释。

http://ar.newsmth.net/thread-de7424203955c0.html

str.lstrip(chars)是说从str左边开始凡是在chars中出现的字符都扔掉,直到第一个不不在chars中出现的字符为止。扔掉的部分不需要和chars中字符的顺序相同,也不需要包括chars中的每一个字符。 


依据这个解释,我试验了一下,确实正确。但是我怎么看,官方的解释不是这样写的啊!!

原文地址:https://www.cnblogs.com/liuyongjians/p/3430482.html