Convert to Uppercase Character in Python || Iterators || Python
In this we are going to see a basic program on how to convert string to uppercase using iterators in Python Programming Language.


class Upper:
    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].islower():
                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 Upper("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

Previous Post Next Post