Iterable and iterator are same yrange class example

when we type the following after writing the class yrange
for x in range(10):
print(x)
why does the above code print all iterated results even when we have not called the next method of yrange class yet?

for x in iterator:
    print(x)

This is possible because the class implemented first is both an iterator and an iterable. This syntax (where we access elements without the next method works for iterables hence it also works for yrange).
See this link for more usage examples.
Hope this helps!

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.