An example Analysis of the working principle of Python iterative Protocol
This article mainly introduces the example analysis of the working principle of Python iterative protocol, which has a certain reference value, and interested friends can refer to it. I hope you will gain a lot after reading this article.
Description
1. The built-in function next () is just a call to the object. Next () function, which is part of the "iterative protocol" and can be found on all iterators.
2. You can do this manually using the next () function (and other parts of the iterative protocol).
It is usually at the expense of readability, so try to avoid doing so.
Example
> x=iter (range (5)) > next (x) 1 > next (x) 1 > next (x) 2 > > next (x) 3 > next (x) 4 > next (x) Traceback (most recent call last): File ", line 1, in StopIteration Thank you for reading this article carefully. I hope the article" example Analysis of the working principle of Python iterative Protocol "shared by the editor will be helpful to you. At the same time, I hope you will support and pay attention to the industry information channel. More related knowledge is waiting for you to learn!