CSC148H1 Lecture Notes - Lecture 5: Mutator Method, Init
katrinasavvy and 38715 others unlocked
1
CSC148H1 Full Course Notes
Verified Note
1 document
Document Summary
The term data encapsulation refers to hiding implementation details from the user/client. The pointer"s y coordinate. x: float y: float def __init__(self, x: float, y: float) -> none: """initalizes a pointer. """ self. set_x(x) self. y = y def _set_x(self, x: float) -> none: A setter method that checks whether it is within appropriate bounds, and if it is, then set it as self. x. Note that methods that start with _ mean that they are private methods and should not be directly called. assert 0 <= x <= 1000 self. _x = x # underscore before a variable name. # means that it is a private variable and that it. # should not be directly accessed. def _get_x(self) -> float: """ returns a float representing the x coordinate""" return self. _x. As you can see above, when an instance of the point class is initialized, the x attribute is au- tomatically passed in through the setter method, self. set x.