Python3-strip()

本文详细介绍了Python中bytearray.strip()方法的使用方法及其参数作用。通过实例演示了如何利用该方法去除字符串两端指定的字符,包括ASCII字符,并展示了不同情况下的应用效果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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的字符

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值