Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

python class getters and setters

class A():
  """Defines a class A with x and y attribute"""
    def __init__(self, x, y):
      """Every instance of A has x and y attributes"""
        self.__x = x #private instance attribute x
        self.__y = y #private instance attribute y
    def GetX(self):
      """Retrieves the x attribute"""
        return self.__x
    def GetY(self):
      """Retrieves the y attribute"""
        return self.__y
    def SetX(self, x):
      """sets the x attribute"""
        self.__x = x
    def SetY(self, y):
      """sets the y attribute"""
        self.__y = y
Source by python-course.eu #
 
PREVIOUS NEXT
Tagged: #python #class #getters #setters
ADD COMMENT
Topic
Name
1+7 =