en_str =" hello world, hello, my name is HanXiaoyang! "# 去空格及特殊符号
en_str.strip().lstrip().rstrip(',')->'hello world, hello, my name is HanXiaoyang!'# 字符串替换
en_str.replace('hello','hi')-> 'hi world, hi, my name is HanXiaoyang!
# 去空格及特殊符号
zh_str =" 大家好,我叫陆超 "
zh_str.strip().lstrip().rstrip(',')->'大家好,我叫陆超'# 字符串替换
zh_str.strip().replace('陆超','寒小阳')->大家好,我叫寒小阳 '
# 删除
zh_str.strip().replace('大家好,','')->'我叫陆超'
# 查找可以用index和find,两者作用一样,但当使用index时字符串中不包含待查找字串时会报错,find不会。
zh_str ="我是陆超;我是李雪琴;我是毛毛姐,好high哟,感觉人生已经达到了高潮,感觉人生已经达到了巅峰"
zh_str.index("陆超")->2#zh_str.index("来了老弟")---------------------------------------------------------------------------
ValueError Traceback (most recent call last)<ipython-input-29-fa2c269b272d>in<module>()---->1 zh_str.index("来了老弟")
ValueError: substring not found
zh_str.index("毛毛姐")->13
zh_str.find("毛毛姐")->13
zh_str.find("来了老弟")->-1
6.大小写与其他变化
en_str ='hello, my name is Patrick'
en_str.lower()->'hello, my name is patrick'
en_str.upper()->'HELLO, MY NAME IS PATRICK'
en_str.capitalize()->'Hello, my name is patrick'#想要查询python字符串的其他方法直接输入help(str)显示出str的所有用法help(str)