0
class Car:
def __init__(self,make,model):
    self.make=make
    self.model=model
def __str__(self):
    return "Car"+str((self.make,self.model))


vwModels=ArrayList()
BMWmodels=ArrayList()
v1=Car("vw","id3")
v2=Car("vw","id4")
vwModels.append(v1)
vwModels.append(v2)
b1=Car("bmw","Series1")
b2=Car("bmw","Series3")
BMWmodels.append(b1)
BMWmodels.append(b2)

Vehicles=[vwModels,BMWmodels]
for i in range(len(Vehicles)):
       print(Vehicles[i])

The output of the printing the array Vehicles has the following:

[<__main__.Car object at 0x7fed2eef1720>, <__main__.Car object at 0x7fed2eef2ad0>]
[<__main__.Car object at 0x7fed2eef20b0>, <__main__.Car object at 0x7fed2eef3220>]

this shows the reference however I would like the output to be the following

[Car("vw","id4"),Car("vw","id3")]
[Car("bmw","Series1"),Car("bmw","Series3")]

i have defined the __str__ function for the Car class but it still doesn't print the desired output

Blockquote

0 Answers0