一、find
检测 str 是否包含在 mystr中,如果是返回开始的索引值,否则返回-1
mystr.find(str, start=0, end=len(mystr))

二、index
跟find()方法一样,只不过如果str不在 mystr中会报一个异常.
mystr.index(str, start=0, end=len(mystr))

三、count
返回 str在start和end之间 在 mystr里面出现的次数
mystr.count(str, start=0, end=len(mystr))

四、replace
把 mystr 中的 str1 替换成 str2,如果 count 指定,则替换不超过 count 次.
mystr.replace(str1, str2, mystr.count(str1))

五、split
以 str 为分隔符切片 mystr,如果 maxsplit有指定值,则仅分隔 maxsplit 个子字符串
mystr.split(str=" ", 2)

六、capitalize
把字符串的第一个字符大写
mystr.capitalize()

七、title
把字符串的每个单词首字母大写
mister.title()

八、startswith
检查字符串是否是以 obj 开头, 是则返回 True,否则返回 False
mystr.startswith(obj)

九、endswith
检查字符串是否以obj结束,如果是返回True,否则返回 False.
mystr.endswith(obj)

十、lower
转换 mystr 中的小写字母为大写
mystr.upper()

十二、ljust
返回一个原字符串左对齐,并使用空格填充至长度 width 的新字符串
mystr.ljust(width)

十三、rjust
返回一个原字符串右对齐,并使用空格填充至长度 width 的新字符串
mystr.rjust(width)

十四、center
返回一个原字符串居中,并使用空格填充至长度 width 的新字符串
mystr.center(width)

十五、lstrip
删除 mystr 左边的空白字符
mystr.lstrip()

十六、rstrip
删除 mystr 字符串末尾的空白字符
mystr.rstrip()

十七、strip
删除mystr字符串两端的空白字符
mister.strip()

十八、partition
把mystr以str分割成三部分,str前,str和str后
mystr.partition(str)

十九、rpartition
类似于 partition()函数,不过是从右边开始.
mystr.rpartition(str)

二十、splitlines
按照行分隔,返回一个包含各行作为元素的列表
mystr.splitlines()

二十一、isalpha
如果 mystr 所有字符都是字母 则返回 True,否则返回 False
mystr.isalpha()

二十二、isdigit
如果 mystr 只包含数字则返回 True 否则返回 False.
mystr.isdigit()

二十三、isalnum
如果 mystr 所有字符都是字母或数字则返回 True,否则返回 False
mystr.isalnum()

二十四、isspace
如果 mystr 中只包含空格,则返回 True,否则返回 False.
mystr.isspace()

二十五、join
mystr 中每个字符后面插入str,构造出一个新的字符串
mystr.join(str)

网友评论