CSC148H1 Lecture Notes - Lecture 3: Docstring, Init

28 views2 pages
1 Feb 2018
School
Course
Professor
katrinasavvy and 38715 others unlocked
CSC148H1 Full Course Notes
1
CSC148H1 Full Course Notes
Verified Note
1 document

Document Summary

When creating a class you always need to implement the class. For example: init method, as that instantiates your. You should also implement special methods like if applicable. For example: eq and str def __eq__(self, other: any) -> bool: """ returns a boolean indicating whether other is equal to self. True return type(self) == type(other) and self. age == other. age. Notice that type was checked rst before other variables, if other. age was checked rst, then since other might not even have the attribute "age", then an attributeerror will be raised. So the type is always checked rst to ensure that they have the neccessary attributes to be checked. If the type is not equal then it would not even check the rest, thus no error will be raised. def __str__(self) -> str: "a husky with the age of 10. " return "a husky with the age of {}". format(self. age) str is called when a class is being printed [print()] or str() is called.

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