I was tasked with creating a program using OOP, reading the documentation they gave me about this task, I have noticed many code examples that use this naming convention:
class User:
def __init__(self, x, y, z):
self.__x = x
self.__y = y
self.__z = z
@property
def x(self):
return self.__x
@property
def y(self):
return self.__y
@property
def z(self):
return self.__z
Is this the pythonic way? I'd go instead with plain attributes, like this:
class User:
def __init__(self, x, y, z):
self.x = x
self.y = y
self.z = z
I don't have much experience with OOP so maybe I'm missing something, in the first example, you have naming mangling protecting the attributes, but I don't know why it is even necessary, as far as I've seen all the modifications to the class attributes are only made within each class, and not from outside. Any ideas on why would the first example make more sense?