**
python封装
**
# 私有成员
class Phone:
# 定义私有成员变量
__current_voltage = 0.5
# 定义私有成员方法
def __keep_single_core(self):
print("让cpu保持单核运行")
def call_by_5g(self):
if self.__current_voltage>=1:
print("5G通话开启")
else:
self.__keep_single_core()
print("电量不足,开启省电模式")
phone = Phone()
phone.call_by_5g()
运行结果:
让cpu保持单核运行
电量不足,开启省电模式