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
答案 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)