Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

13
  • 1
    @Not_here_to_play I think you understood the problem. I don't quite understand your question about self._age, but maybe this helps: the point of self._age is to store the age value in a "normal" instance variable that does not run getter or setter logic when accessed (unlike self.age). Commented Sep 30, 2021 at 9:59
  • 1
    @Not_here_to_play so self.age calls functions when being accessed or set. These functions may do something with self._age, where the actual age value is stored, "hidden" from the user. Commented Sep 30, 2021 at 10:02
  • 1
    @Not_here_to_play self._age is a normal instance variable that you did not define as a property, so no getter or setter logic is run when you get or set it. Rename self._age to self.the_numeric_age_value in your head. It's completely decoupled from self.age, you just happen to access/set in the body of get_age or set_age. Commented Sep 30, 2021 at 10:13
  • 1
    @Not_here_to_play "how on earth do i get self._age and not self.age when I run print(self.age)" <- by returning self._age in get_age. Commented Sep 30, 2021 at 11:17
  • 1
    @Not_here_to_play _age is not a property, it's a normal instance variable. If it was a property like age, it would have its own setters and getters. Commented Sep 30, 2021 at 14:00