码迷,mamicode.com
首页 > 编程语言 > 详细

Python : Data Encapsulation

时间:2014-10-26 21:02:13      阅读:274      评论:0      收藏:0      [点我收藏+]

标签:style   blog   io   strong   sp   div   on   log   bs   

Python : Data Encapsulation

The following table shows the different behaviour:

NameNotationBehaviour
name Public Can be accessed from inside and outside
_name Protected Like a public member, but they shouldn‘t be directly accessed from outside.
__name Private Can‘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

标签:style   blog   io   strong   sp   div   on   log   bs   

原文地址:http://www.cnblogs.com/bittorrent/p/4052697.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!