Surprisingly, I find startswith is slower than in:
In [10]: s=\"ABCD\"*10
In [11]: %timeit s.startswith(\"XYZ\")
1000000 loops, be
This is likely because str.startswith() does more than str.__contains__(), and also because I believe str.__contains__ operates fully in C, whereas str.startswith() has to interact with Python types. Its signature is str.startswith(prefix[, start[, end]]), where prefix can be a tuple of strings to try.