3 ms·
> Technically not - the right thing to do is return the number of characters[0] > 0: or bytes, but that's trivial In what encoding? The utf-8, utf-32, and utf
by joshuamorton 7y ago
> Technically not - the right thing to do is return the number of characters[0]
> 0: or bytes, but that's trivial
In what encoding? The utf-8, utf-32, and utf-16 encodings of the same string are different numbers of bytes.
- a1369209993 7y agoNumber of bytes would apply in cases - like the len() of a python3 bytes or python str object, or something like C's strlen function - where you're not operating on characters in the first place. It's trivial precisely because there is no encoding. "\xC4\xAC" is two bytes regardless of whether you interpret it as [latin capital i + breve] or [hangul gyeoh] or [latin capital a + umlaut][not sign] ("Ĭ" / "곃" / "Ĭ").