使用string.count()方法时,我收到一个错误,TypeError:期望一个字符缓冲区对象

时间:2015-05-21 10:40:23

标签: python count

s = "That that is is that that is not is not is that it it"
sub = "s"
print "str.count(sub, 4, 40) : ", str.count(sub, 4, 40)

使用string.count()方法时收到以下错误。

错误:

TypeError: expected a character buffer object

1 个答案:

答案 0 :(得分:2)

不要在str类上调用该方法,而是调用字符串对象:

s = "That that is is that that is not is not is that it it"
sub = "s"
print "s.count(sub, 4, 40) : ", s.count(sub, 4, 40)