0
点赞
收藏
分享

微信扫一扫

封装的思想练习

最不爱吃鱼 2022-03-23 阅读 45
python
"""
设计:Python程序设计
作者:初学者
日期:2022年 03月 22日
"""


class Person:
    def __init__(self, name):
        self.name = name

    @property
    def name(self, ):
        return self.__name

    @name.setter
    def name(self, value):
        self.__name = value

    def go_to(self, str_postion, type):
        print(self.name, "去", str_postion)
        type.run(str_postion)


class Car:
    def run(self, str_postion):
        print("开车去", str_postion)


person = Person("老王")
car = Car()
person.go_to("湖南", car)

举报

相关推荐

0 条评论