python类的属性
来源:互联网 发布:h3c网管软件 编辑:程序博客网 时间:2024/05/22 13:26
一 介绍
1、在python中,如果属性是以双下划线开始的,则该属性是私有属性。
2、如果在类内部使用私有属性,则应该在私有属性前加上"self."。
二 代码示例
>>>class book:
__author =''
__name =''
__page =0
price =0
__press =''
>>> a = book()
>>> a.__author
Traceback(most recent call last):
File"<pyshell#9>", line 1,in<module>
a.__author
AttributeError:'book' object has no attribute '__author'
>>> a.price
0
>>> a.price =20
>>> a.price
20
>>> a.__name
Traceback(most recent call last):
File"<pyshell#13>", line 1,in<module>
a.__name
AttributeError:'book' object has no attribute '__name'
>>> a.__page
Traceback(most recent call last):
File"<pyshell#14>", line 1,in<module>
a.__page
AttributeError:'book' object has no attribute '__page'
阅读全文
0 0
- Python--类的属性
- Python类的属性
- python-类的属性
- python类的属性
- python的类属性和实例属性
- python的类属性和实例属性
- python 的 类属性 与 实例属性
- python的类属性和实例属性
- python的类属性和实例属性
- python的类属性和实例属性
- Python Class的实例属性/类属性
- python中类的属性
- python 类的数据属性
- Python 类属性的理解
- python的类属性问题
- Python类的特殊属性
- python 特殊的类属性
- Python 类的内置属性
- Kubernetes对象之Nodes和 Master与Node的通信
- Tomcat配置域名
- Java反射机制原理剖析
- python的类的方法
- ORACLE强制索引
- python类的属性
- python中的单继承
- 进制
- Spring3MVC通过SpringContextUtil获取上下文(与不使用对比)
- OpenCV实践之路——人脸识别之三识别自己的脸
- Tensorflow实战学习(四十三)【TF.Learn 机器学习Estimator,DataFrame,监督器Monitors】
- 13.3Groovy向具体的实例(对象)中注入方法,使不同的对象有不同的方法(神奇不)
- python中的多继承
- Android Canvas画图形(更新中)