Bytes Methods
bytes.count()
Count non-overlapping occurrences of the binary subsequence. Searches accept a bytes-like object or a single integer byte (0–255). Bounds restrict complete matches; offsets are relative to the original sequence. Returns zero when absent. Empty patterns match boundaries, but a start greater than the original length does not match. Positions count bytes, not decoded characters. Integer search support was added in Python 3.3.
Formal Syntax & Structure
python syntaxpython
data.count(sub[, start[, end]])Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| sub | bytes-like | int | Binary subsequence or single byte value from 0 through 255. |
| start | int | None | Inclusive search start; negative values count from the end. |
| end | int | None | Exclusive search end; defaults to the end of the data. |
Return Value
int
Number of non-overlapping matches.
Working Example
Example Snippetpython
print(bytes(b'AB:AB:Z').count(b'AB'))print(bytes(b'AB:AB:Z').count(58))print(bytes(b'AB:AB:Z').count(memoryview(b'AB'), 1, 6))