Strip () method syntax: Str.strip ([chars]); Declaration: STR is a string and RM is a sequence of characters to be deleted
- Str.strip (RM) Delete character in
开头、结尾处 a string that is located in RM delete sequence
eg1:#首尾端‘0‘被删除,中间不动>>> t=‘0000this is string example0000wow!!!0000‘>>> t.strip(‘0‘)‘this is string example0000wow!!!‘eg2:#无入参,默认删除首尾所有空字符 ‘\n\t空格‘>>>s=‘\n 0000this is string example0000wow!!!0000\n \t‘>>> s.strip()‘0000this is string example0000wow!!!0000‘
- Str.lstrip (RM) Delete character in
开头处 a string that is located in RM delete sequence
t=‘0000this is string example0000wow!!!0000‘>>> t.lstrip(‘0‘)‘this is string example0000wow!!!0000‘#空入参同样可删除首部空字符,‘.rstrip()‘同理s=‘\n 0000this is string example0000wow!!!0000\n \t‘>>> s.lstrip()‘0000this is string example0000wow!!!0000\n \t‘
- Str.rstrip (RM) Delete character in
结尾处 a string that is located in RM delete sequence
t=‘0000this is string example0000wow!!!0000‘>>> t.rstrip(‘0‘)‘0000this is string example0000wow!!!‘s=‘\n 0000this is string example0000wow!!!0000\n \t‘>>> s.rstrip()‘\n 0000this is string example0000wow!!!0000‘
What is the ' end and end '? of the experiment
s=‘\n 0000this is string is example0000wow!!!0000\n \t‘>>> s.lstrip(‘\n 0‘)‘this is string is example0000wow!!!0000\n \t‘#首部‘\n 0000‘被删除>>> s.lstrip(‘\n 0this‘)‘ring is example0000wow!!!0000\n \t‘#奇妙啊,我的目标是删除首部‘\n 0000this‘,结果‘\n 0000this is st‘全被删除,说明:符合入参(‘\n 0this‘)的字符皆是删除对象,不论字符顺序#但,为何string后面的is没有删除?因为,‘首部‘指的是‘连续符合‘入参要求的字符,string中的‘r‘隔断了入参的连续字符要求,python判定首部结束。
The experiment proves that: the so-called first and the end, the judgment basis is-是否连续符合入参要求, if it fits, regardless of order, can be operated, until it encounters第一个非入参字符So far.
Python strip () function inquiry