我们一起归总一下python字符串中,常见的一些操作吧 !
"find"的用法是表示出索引值所在的位置,用数字表示如下图所示:

“index”跟“find”有一些差异,find打出的要求里要是没有所需要求,它就会报出负值,index打出mystr里没有的条件,那么它就会报错!如图所示:

“count”的用法是计算出mystr里某个词组出现了一共多少次,如图所示:

"replace"的用法是可以替换mystr中的某一单词替换成另一个单词,效果如图所示:

"split"的用法是把整句分割成一个词组一个词组的显示出来,如图所示:

capitalize的用法是把字符串的首个字母改成大写的,如图所示:

“title”的用法是把字符串里的每一个单词的首字母变成大写的,如图所示:

“startswith”的作用是检查字符串的开头是否以obj开头,如果是,就显示True,如果不是就显示False,如图所示:

"endswith"的用法是检查字符串的末尾是否以ojb结尾,如果是就显示True,如果不是就显示False,如图所示:

网友评论