In this we are going to see a basic program to convert strings to lowercase using iterators in Python Programming Language.
class Lower:
def __init__(self, s):
self.s = s
self.l = len(self.s)
def __iter__(self):
self.c = 0
return self
def __next__(self):
res = ""
if self.c < self.l:
if self.s[self.c].isupper():
res = chr(ord(self.s[self.c])+32)
else:
res = self.s[self.c]
self.c += 1
return res
else:
raise StopIteration
for i in Lower("HeLlo"):
print(i, end="")
# Coded by Saahil
#ENJOY CODING
Post a Comment
FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP