python Class definition

96
unspecx
2019.05.08 15:27 字数 3

class ClassThis:

  # class variable shared by all instances
  classVariable='this is a class variable'
  _protectedClassVariable=''
  __privateClassVariable=''

  def __init__(self, instanceVariableValue, value1, value2):

            # instance variable unique to each instance
            self.instanceVariable=instanceVariableValue

            # protected实例变量,尽可以被当前类和子类访问
            self._protectedInstanceVariable=value1

            # private实例变量,尽可以被当前类访问
            self.__privateInstanceVariable=value2
派森
Web note ad 1