python学习笔记0001
数据类型&一些基本操作
字符串,整型、浮点型、元组、字典、列表。。。
对字符串可以进行切割
S.split(“要切割的元素”)
也可以对字符串进行切片
S[M:N:K] [起始位置:结束位置+1:步长(默认为1 )]
也可以对字符串进行替换
S.replace(old, new[, max])
Python replace() 方法把字符串中的 old(旧字符串) 替换成 new(新字符串),如果指定第三个参数max,则替换不超过 max 次
例如:
str = “this is string example…wow!!! this is really string”;
print str.replace(“is”, “was”);
print str.replace(“is”, “was”, 3);
控制台就会输出:
thwas was string example…wow!!! thwas was really string
thwas was string example…wow!!! thwas is really string