CSE 1010 Lecture Notes - Lecture 29: Iter, Iterator, Inex

59 views3 pages
Verified Note

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.

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers