PEP 393 vs UTF-8 Everywhere

Chris Kaynor ckaynor at
Fri Jan 20 18:37:44 EST 2017

On Fri, Jan 20, 2017 at 3:15 PM, Thomas Nyberg <tomuxiong at> wrote:
> On 01/20/2017 03:06 PM, Chris Kaynor wrote:
>>         [...snip...]
>> --
>> Chris Kaynor
> I was able to delete my response which was a wholly contained subset of this
> one. :)
> But I have one extra question. Is string indexing guaranteed to be
> constant-time for python? I thought so, but I couldn't find it documented
> anywhere. (Not that I think it practically matters, since it couldn't really
> change if it weren't for all the reasons you mentioned.) I found this which
> at details (if not explicitly "guarantees") the complexity properties of
> other datatypes:

As far as I'm aware, the language does not guarantee it. In fact, I
believe it was decided that MicroPython could use UTF8 strings with
linear indexing while still calling itself Python. This was very
useful for MicroPython due to the platforms it supports (embedded),
and needing to keep the memory footprint very small.

I believe Guido (on Python-ideas) has stated that constant-time string
indexing is a guarantee of CPython, however.

The only reference I found in my (very quick) search is the Python-Dev
thread at!msg/dev-python/3lfXwljNLj8/XxO2s0TGYrYJ

More information about the Python-list mailing list