Home  >  Article  >  Backend Development  >  Python 面向对象 成员的访问约束

Python 面向对象 成员的访问约束

WBOY
WBOYOriginal
2016-06-06 11:27:041216browse

在Python中是通过一套命名体系来识别成约的访问范围的
class MyObjec(object):
username = "developerworks" # public
_email = "developerworks#163#.com" #protected
__tel = "1391119****" # private
从这段代码中可以看出一些巧妙的命名方法
在python中所有的以字母开头的成语名称被python命名体系自动识别为public,单个下划线开头的成员被识别为protected,最后双下划线开头的成员被识别为private。python的简洁和优美就在于此。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn