def count(s, sub, i = 0, last=None):
	"""count(s, sub[, start[,end]]) -> int

	Return the number of occurrences of substring sub in string
	s[start:end].  Optional arguments start and end are
	interpreted as in slice notation.

	"""
	Slen = len(s)  # cache this value, for speed
	if last is None:
		last = Slen
	elif last < 0:
		last = max(0, last + Slen)
	elif last > Slen:
		last = Slen
	if i < 0: i = max(0, i + Slen)
	n = len(sub)
	m = last + 1 - n
	if n == 0: return m-i
	r = 0
	while i < m:
		if sub == s[i:i+n]:
			r = r+1
			i = i+n
		else:
			i = i+1
	return r