Python bytes.removesuffix() 方法及代码示例

bytes.removesuffix(suffix, /):如果二进制数据以后缀字符串结尾且后缀非空,返回 bytes[:-len(suffix)] 。否则,返回原始二进制数据的复制

初见版本

3.9

定义

bytes.removesuffix(suffix, /)

bytearray.removesuffix(suffix, /)

参数

参数类型参数名称参数描述
bytes-like objectsuffix后缀对象

示例

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'