Generators to Represent Infinite Sequences Iterators are used to represent infinite sequences.In this course,when we ask you to write an iterator,we want you to write a generator. >>def naturals(): X=0 while True: yield x X+=1 >>nats naturals() >>next(nats) 0 >>next(nats) 1 >>nats1,nats2 naturals(),naturals() >>[next(nats1)*next(nats2)for _in range(5)] [0,1,4,9,16]Squares the first 5 natural numbersGenerators to Represent Infinite Sequences Iterators are used to represent infinite sequences. In this course, when we ask you to write an iterator, we want you to write a generator. >>> def naturals(): ... x = 0 ... while True: ... yield x ... x += 1 >>> nats = naturals() >>> next(nats) 0 >>> next(nats) 1 >>> nats1, nats2 = naturals(), naturals() >>> [next(nats1) * next(nats2) for _ in range(5)] [0, 1, 4, 9, 16] # Squares the first 5 natural numbers