In this we are going to see a basic program on iterable object to print even numbers till limit in Python Programming Language.
class Even:
def __init__(self, l):
self.l = l
def __iter__(self):
self.n = 0
return self
def __next__(self):
if self.n <= self.l:
res = self.n
self.n += 2
return res
else:
raise StopIteration
for i in Even(100):
print(i)
# Coded by Saahil
#ENJOY CODING
Post a Comment
FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP