一字符串格式化操作
比较详细
www.cnpythoner.com/wiki/string.html

<1>常用的格式符号
下面是完整的,它可以与%符号使用列表:

二字符串常见操作
<1>find
如有字符串mystr = 'hello world itcast and itcastcpp',以下是常见的操作。
检测 str 是否包含在 mystr中,如果是返回开始的索引值,否则返回-1
mystr.find(str, start=0, end=len(mystr))

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

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

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

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













网友评论