In C-ish languages, I’d mask data storage details with getter/setter methods/functions like:
int getFoo();
void setFoo(int value);
I have some Python that does:
class MyClass:
def Foo(self):
...magic to access foo...
return value
What’s the right way to write/name a setter for Foo? I’m sure it’s more idiom than language feature but I’m not sure what’s common. Maybe I need to rename Foo() to getFoo() and match it with setFoo(). I guess that’s OK if that’s what is usually done.
Use the builtin property function:
Now you can use access it like this:
It will print: