一、rstrip的用法
rstrip是删除字符串末尾的字符,不写的话是空格
str = ’ hello, world! ’
print(str.rstrip())
str2 = ‘000000000 hello, world! 000000000000’
print(str2.rstrip(‘0’))
运行结果:
二、lstrip的用法
lstrip是删除字符串前端的字符,不写的话是空格
str = ’ hello, world! ’
print(str.rstrip())
str2 = ‘000000000 hello, world! 000000000000’
print(str2.lstrip(‘0’))
运行结果:
三、strip的用法
strip是删除字符串前面和后面的字符,不写的话是空格
str = ’ hello, world! ’
print(str.rstrip())
str2 = ‘000000000 hello, world! 000000000000’
print(str2.strip(‘0’))
运行结果: