immutable variable

PHOTO EMBED

Sun Feb 27 2022 08:10:57 GMT+0000 (Coordinated Universal Time)

Saved by @armin10020 #python

class Inf:
    def __iter__(self):
        self.start = 0
        return self

    def __next__(self):

        num = self.start
        self.start += 2
        return num
content_copyCOPY

start = 0 num = start --> num = 0 num +=2 --> num =0+ 2 #it creat new variable and it point to new object cause int is immutable, and it eleminate "num" variable start is still 0, cause then previous "num" eliminated when it re assign as it was int ___________ num = start --> num = 2 --> so previous num will eleminate and new num object will creat ...