python的字符串的长度
python 字符串长度
通过内置方法len()来计算字符串的长度,注意这个计算的是字符的长度。
aa = 'afebb'
bb = '你'
print len(aa)
print len(bb)
python字符串的替换
a = 'hello word'
b = a.replace('word','python')
print b
如何使用python语言中的字符串方法判断字符存在
str.endswith(suffix[, start[, end]])
参数
suffix – 该参数可以是一个字符串或者是一个元素。
start – 字符串中的开始位置。
end – 字符中结束位置。
str = "this is string example....wow!!!";
suffix = "wow!!!";
print str.endswith(suffix);
print str.endswith(suffix,20);
suffix = "is";
print str.endswith(suffix, 2, 4);
print str.endswith(suffix, 2, 6);
以上实例输出结果如下:
True
True
True
False