首页 > 代码库 > Python : Data Encapsulation

Python : Data Encapsulation

Python : Data Encapsulation

The following table shows the different behaviour:

NameNotationBehaviour
namePublicCan be accessed from inside and outside
_nameProtectedLike a public member, but they shouldn‘t be directly accessed from outside.
__namePrivateCan‘t be seen and accessed from outside

 

 

 

 

e.g. 

class Account(object):     counter = 0    def __init__(self, holder, number, balance,credit_line=1500):         Account.counter += 1        self.__Holder = holder         self.__Number = number         self.__Balance = balance        self.__CreditLine = credit_line    def __del__(self):        Account.counter -= 1

  



Python : Data Encapsulation