Python - 私有方法,专有方法
来源:互联网 发布:好的监控软件 编辑:程序博客网 时间:2024/06/14 16:42
Python的私有方法:以'__'双划线开头,但不以双划线结尾, __privateMethod
专有方法:以双划线开头和结尾, __init__
e.g
class Person: def __init__(self,name): self.name = "Person" def __getName(self): return self.name
<pre style="color: rgb(0, 0, 0); font-family: 'Courier New'; font-size: 9pt; background-color: rgb(255, 255, 255);"><span style="background-color: rgb(255, 228, 255);">aPerson</span> = Person(<span style="color: rgb(0, 128, 0); font-weight: bold;">'test'</span>)<span style="background-color: rgb(228, 228, 255);">aPerson</span>.getName()
结果: aPerson.getName()
AttributeError: Person instance has no attribute 'getName', 因为是私有所以会报错哦。
而__init__就是一个初始化函数,典型的专有函数
0 0
- Python - 私有方法,专有方法
- Python之私有函数和专有方法
- python类的专有方法
- [随记]python类的专有方法
- python中的类专有的方法
- Python 访问私有变量和私有方法
- python之私有属性及私有方法
- Python----伪私有属性和私有方法
- python私有方法和变量
- Python 私有变量、私有方法、类变量与实例变量
- Python类中的 私有变量和私有方法
- python对象:访问私有属性和私有方法
- Python(私有变量)类中的特殊方法
- Python(私有变量)类中的特殊方法
- Python(私有变量)类中的特殊方法
- Python(私有变量)类中的特殊方法
- Python(私有变量)类中的特殊方法
- Python(私有变量)类中的特殊方法
- svn教程
- 欢迎使用CSDN-markdown编辑器
- CollapsingToolbarLayout
- ioctl()函数详解
- Python三维数组
- Python - 私有方法,专有方法
- R data.table系统学习
- microstation level2 liner pattern
- LINUX查看系统资源命令
- linux查看系统信息
- CentOS环境下使用GIT基于Nginx的私服搭建全过程
- RS-485半双工延时问题
- Hadoop简介(1):什么是Map/Reduce
- 实现向 python 脚本中传递列表,字典参数