Python3-strip()

来源:互联网 发布:喝咖啡的利弊 知乎 编辑:程序博客网 时间:2024/04/30 08:45

bytearray.strip([chars])
Return a copy of the sequence with specified leading and trailing bytes removed. The chars argument is a binary sequence specifying the set of byte values to be removed - the name refers to the fact this method is usually used with ASCII characters. If omitted or None, the chars argument defaults to removing ASCII whitespace. The chars argument is not a prefix or suffix; rather, all combinations of its values are stripped:

>>> b'   spacious   '.strip()b'spacious'>>> b'www.example.com'.strip(b'cmowz.')b'example'

关于strip()的几个测试:

print('www.example.com'.strip('cmowz.'))>>>example
print('wwwexamplecom'.strip('cmowz.'))>>>example
print('www.example.com'.strip('mowz.'))>>>example.c

由此可见,strip(’s’)就是将首尾中的s删除,直到不是s的字符

0 0
原创粉丝点击