What is the meaning of generator in python
This article will explain in detail what the generator in python means. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.
Generator (Generator):
Through list generation, we can create a list directly. However, due to memory constraints, the list capacity is certainly limited. Moreover, creating a list of 1 million elements not only takes up a lot of storage space, but if we only need to access the first few elements, the space occupied by most of the later elements is wasted. In Python, this mechanism of calculating while looping is called a Generator.
Here is a simple generator:
> L = [x * x for x in range (10)] > L [0,1,4,9,16,25,36,49,64,81] > > g = (x * x for x in range (10)) > > g this article on "what is the meaning of generator in python" ends here. I hope the above content can be helpful to you so that you can learn more knowledge. Please share it for more people to see.