CSE 1010 Lecture Notes - Lecture 29: Iter, Iterator, Inex
CSE 1010 verified notes
29/29View all
Document Summary
Cse 1010 - introduction to computing for engineers. The square class can be rewritten like this: class square(shape): #the square class inherits both methods from the shape class, as well as. #class with these new methods def __init__(self, side, color): print( square. __init__ side= , side) #works, too self. _color = color self. _side = side. 2 def printit(self): super(). printit() print( i am a , self. __class__. __name__, my size is , self. _size) #these statements are not inside any class, but you can test what. Iterator example: class myiterable: def __init__(self, letters): self. _letters = letters def __iter__(self): #this function just reverses the characters in. #a string and prints them lst = [] for n in range(len(self. _letters)): #this for loop might be lst. append(self. _letters[len(self. _letters) - n - 1]) #another way to write __iter__ is by doing this (because you can"t. #technically reverse a string, but you can reverse a list.