Thursday, January 28, 2021

python day26

 # -*- coding: utf-8 -*-

"""

Created on Thu Jan 28 21:45:09 2021

day 26

iterators 


@author: anil


flowers=("jasmin","marigold","lilli")

#print(type(flowers))


#iterators

#__iter__()

#iter()

#

'''

print(iter(flowers))

print(flowers[0])

print(flowers[1])

print(flowers[2])

'''


myiter=iter(flowers)

print(myiter)

"""


#flowers=("jasmin","marigold","lilli","malle","rose")

#print(type(flowers))


#iterators

#__iter__()

#iter()

#

'''

print(iter(flowers))

print(flowers[0])

print(flowers[1])

print(flowers[2])



myiter=iter(flowers)

#print(myiter)


print(next(myiter))

print(next(myiter))

print(next(myiter))

print(next(myiter))

print(next(myiter))





flowers=["jasmin","marigold","lilli","malle","rose"]

myiter=iter(flowers)

#print(myiter)


for i in range(5):

    print(next(myiter))



class numbers:

    def __iter__(self):

        self.a=1

        return self

    

    def __next__(self):

        x=self.a

        self.a=self.a+1

        return x

    


my_class=numbers()

myiter=iter(my_class)


print(next(myiter))

print(next(myiter))

print(next(myiter))

print(next(myiter))


#StopIteration(args)

'''



class numbers:

    def __iter__(self):

        self.a=1

        return self

    

    def __next__(self):

        if self.a<=30:

            x=self.a

            self.a=self.a+1

            return x

        else:

            raise StopIteration

    


my_class=numbers()

myiter=iter(my_class)



for i in range(30):

    print(next(myiter))



#StopIteration(args)

python class topic video