###私有方法的调用
# 测试私有属性、私有方法
class Employee:
def __init__(self, name, age):
self.name = name
self.__age = age # 私有实例属性
def __work(self):
print("好好学习,天天向上")
print("年龄:{0}".format(self.__age))
p1 = Employee("高淇", 32)
print(p1.name)
print(p1._Employee__age)
print(dir(p1)) # p1.say_company()
p1._Employee__work()
输出结果:
D:\work\python\three\venv\Scripts\python.exe D:\work\python\three\mypy11.py
高淇
32
['_Employee__age', '_Employee__work', '__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__', 'name']
好好学习,天天向上
年龄:32
标签:__,p1,私有,age,99,print,Employee,方法,self From: https://www.cnblogs.com/yuanzijian/p/16906414.html