1 Star 0 Fork 0

巧克力ovo/PythonLearn

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
5-2.py 637 Bytes
一键复制 编辑 原始数据 按行查看 历史
wlt 提交于 1个月前 . 5
class Car:
def __init__(self, make, model, year):
self.make = make
self.model = model
self.year = year
def __display_info(self):
# 私有方法,用于显示汽车信息
print(f"Car Make: {self.make}, Model: {self.model}, Year: {self.year}")
def drive(self):
# 在类内部调用私有方法
self._Car__display_info() # 使用类名加方法名的方式调用私有方法
print(f"The {self.make} {self.model} is now driving.")
# 创建对象
car1 = Car("Toyota", "Corolla", 2020)
car2 = Car("Honda", "Civic", 2021)
# 调用方法
car1.drive()
car2.drive()
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/chocolate-ovo/python-learn.git
git@gitee.com:chocolate-ovo/python-learn.git
chocolate-ovo
python-learn
PythonLearn
master

搜索帮助