在学习python的跨类调用时遇到了一个问题
代码能运行但是输出的是内存地址
class Peason():
def __init__(self, name):
self.name = name
def go_to(self, place, vehice):
self.place = place
self.vehice = vehice
self.vehice.run()
print(f"{self.name}驾驶{self.vehice.brand}{self.vehice}去{self.place}")
class Car():
def __init__(self, brand):
self.brand = brand
def run(self):
print("行驶")
lz = Peason("老张")
car = Car("奔驰")
lz.go_to("东北", car)
行驶
老张驾驶奔驰<__main__.Car object at 0x7f8380dcdd90>去东北
暂时没有什么想法
我想通过参数去传递每次使用的交通工具也就是不想把使用的交通工具写死 并且能够正确输出结果而不是输出内存地址