CSE 1010 Lecture Notes - Lecture 23: Init

94 views2 pages
Verified Note

Document Summary

Cse 1010 - introduction to computing for engineers. Continuing the class: class checkingaccount (bankaccount): def writecheck(self, to, amount): def depositcheck(self, check): All we need to do is inherit from bankaccount and then add these two new methods from above. The shape class: class shape: def __init_(self, color): self. _color = color def getcolor(self): return self. _color. Square subclass (of the shape class) import shape class square(shape. shape): def __init__(self, side): def area(self): self. _side = side return self. _side ** 2. This method replaces the __init__ method that was inherited from the. A method is a function inside a class: You can call a method like a function, but you need to supply the argument for self. The getcolor method in the shape class needs a single argument, and it should be a shape instance. Now, let"s look at the shape __init__ method from above: def __init__(self, color): Shape"s __init__ method/function requires a shape instance and a color.

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

Related Documents