我刚刚开始学习
python,我对如何传递一个对象的实例作为一个函数的参数感到困惑,下面是我为练习做的一些代码,基本的想法是有一个车库,这个车库不包含汽车,您可以将车辆添加到车库并查看其详细信息.
class Garage:
cars = []
def add_car(self, car):
cars.append(car)
class Car:
car_name, car_price, car_colour, car_miles, car_owners = "", "", "", "", ""
def add_new_car(self, garage, name, price, colour, miles, owners):
car_name = name
car_price = price
car_colour = colour
car_miles = miles
car_owners = owners
garage.add_car(self)
def main(argv=None):
your_garage = Garage()
while True:
print "Your garage contains %d cars!" % len(your_garage.cars)
print "1) Add a new car\n2) View your car's\n0) Leave the garage"
user_input = raw_input("Please pick an option: ")
if