str常用函数endswith()、split()、strip()

print(type('100m'.endswith('m')))   # 判断目标字符串是否以某字符结尾
print('100m'.endswith('m'))
>> <class 'bool'>
>> True
print(type('100m100m1'.split('m')))   # 将目标字符串以某字符分离
print('100m100m1'.split('m'))
>> <class 'list'>
>> ['100', '100', '1']
print(type('100m100m11'.strip('m')))   # 去除目标字符串尾部的某类字符
print('100m100m11mmm'.strip('m'))
>> <class 'str'>
>> 100m100m11

.
.
.
2019-03-20 15:37:48写于上海

猜你喜欢

转载自blog.csdn.net/The_Time_Runner/article/details/88690568