CSC148H1 Lecture Notes - Lecture 3: Docstring, Init
katrinasavvy and 38715 others unlocked
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.