Open kamocat opened 13 hours ago
Adafruit CircuitPython 9.1.4 on 2024-09-17; Raspberry Pi Pico with rp2040
a = b'A' * 32 print(a.count(b'A')) print(a.count(65)) #A is ascii character 65
The count function works with the byte string but not the integer. See:
32 Traceback (most recent call last): File "code.py", line 3, in <module> TypeError: can't convert 'int' object to str implicitly
In contrast, with cPython 3.12.6 in win32, the count works with both the integer and the byte string:
>>> a = b'A' * 32 >>> a.count(b'A') 32 >>> a.count(65) 32
https://docs.python.org/3/library/stdtypes.html#bytes.count states
The subsequence to search for may be any bytes-like object or an integer in the range 0 to 255.
This behavior also exists in MicroPython, from which we take a lot of this kind of core functionality.
CircuitPython version
Code/REPL
Behavior
The count function works with the byte string but not the integer. See:
Description
In contrast, with cPython 3.12.6 in win32, the count works with both the integer and the byte string:
Additional information
https://docs.python.org/3/library/stdtypes.html#bytes.count states