Python3中操作字符串str必须记住的几个方法

如题所述

split([sep]) 将字符串分割为列表,默认用空白符分割,给出字符串参数,用参数字符串分割
'a b c'.split() 返回 ['a','b','c']
join 将可迭代对象中的字符串连接在一起
'\n'.join(['a','b','c'] )返回字符串 "a\nb\nc"
str.find(substr,[start,[end]]) 从str的下标 start至end之间查找substr,返回substr出现位置的下标,未找到返回-1
str.index 与find相仿,但未找到抛出异常
其余还要通用的下标 ,切片操作等
温馨提示:答案为网友推荐,仅供参考
第1个回答  2018-05-31
分割,替换,
split,replace