封装的思想练习

阅读 45

2022-03-23

"""
设计: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)

0 0 举报