It is my understanding that the range() function, which is actually an object type in Python 3, generates its contents on the fly, similar to a generator.
TLDR;
range is an arithmetic series so it can very easily calculate whether the object is there.It could even get the index of it if it were list like really quickly.