Clearly, len has some overhead and since it does a function call and makes an interpretation of AttributeError to TypeError. Additionally, set.__len__ is a particularly basic operation that it will undoubtedly be exceptionally quick in contrast with pretty much anything, yet I actually don't discover anything like the 14x distinction when utilizing timeit:
In : s = set()
In : %timeit s.__len__()
1000000 loops, best of 3: 197 ns per loop
In : %timeit len(s)
10000000 loops, best of 3: 130 ns per loop
You should in every case simply call len, not __len__. In the event that the call to len is the bottleneck in your program, you should reexamine its design, for example, cache measures someplace or ascertain them without calling len.
Are you pretty much interested to learn python in detail? Come and join the python training course to gain more knowledge.