Python bytes.removesuffix() 方法及代码示例
bytes.removesuffix(suffix, /):如果二进制数据以后缀字符串结尾且后缀非空,返回 bytes[:-len(suffix)] 。否则,返回原始二进制数据的复制
初见版本
3.9定义
bytes.removesuffix(suffix, /)
或
bytearray.removesuffix(suffix, /)
参数
参数类型 | 参数名称 | 参数描述 |
---|---|---|
bytes-like object | suffix | 后缀对象 |
示例
byte = b'21yi.com' print(byte, ".removesuffix:", byte.removesuffix(b'.com')) byte = b'BaseTestCase' print(byte, ".removesuffix:", byte.removesuffix(b'Test'))
执行结果为 :
b'21yi' b'BaseTestCase'