CSCA20H3 Lecture : Class.docx

75 views3 pages
School
Course
Professor

Document Summary

-this is a constructor: a method that will be run whenever a new. --this method (after definition) is an operation you can run on the new type. -need to define the lightness medhto d def lightness(self): you start with def __init__(self,r,b,g): self,red= self strongest=max(self. red, self. green, self,blue) -you don"t want to use this method anymore, but replace it with __init__ the special methods __name__ such as __init__ __add__ so next time when you are creating a new class, just def the __init__ and then def the. __str__( which is contingent on the __init__), and then the lightness method class color(object): """an rgb color, with red, green and blue components. """ def __init__(self, r, g, b): """a new color with red value r, green value g, and blue value b. All components are integers in the range 0-255. """ self. red = r self. green = g self. blue = b def __str__(self): """return a string representation of this color in the form.

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

Related Questions