python私有成员都以双下划线“__”开头,仅类内部可访问
2021/5/31 1:20:15
本文主要是介绍python私有成员都以双下划线“__”开头,仅类内部可访问,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
- python私有成员都以双下划线“__”开头,仅类内部可访问。
私有成员不能在本类外面使用,起到一个保护的作用,只能类内部使用。下面类中的self.__age, def __getName分别为私有对象和私有方
- dir(对象):查看对象上的属性和方法
print(dir(teacher))
['_Teacher__age', '_Teacher__getName', '__class__', '__delattr__', '__dict__', '__dir__', '__doc__',
'__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__',
'__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__',
'__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'getAge', 'name']
这篇关于python私有成员都以双下划线“__”开头,仅类内部可访问的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-05-08有遇到过吗?同样的规则 Excel 中 比Python 结果大
- 2024-03-30开始python成长之路
- 2024-03-29python optparse
- 2024-03-29python map 函数
- 2024-03-20invalid format specifier python
- 2024-03-18pool.map python
- 2024-03-18threads in python
- 2024-03-14python Ai 应用开发基础训练,字符串,字典,文件
- 2024-03-13id3 algorithm python
- 2024-03-13sum array elements python