Python 101: Changing the behavior of the "range" function


We create an custom iterator function that we will use with a "for" loop:


We use it as below:


The "yield" function acts as a return function but it doesn't completely  exit the function - the control is not handed back completely to the caller of the function - and the next instruction in the function is run:

Comments

Popular posts from this blog

Istio 101 : How Istio ServiceEntry relates to Kubernetes Services and Endpoints

Kubernetes 101 : - Scaling a Stateful set -

Python 101 : Generators and Lists