0
Class atribbutes printing
For example: class Car(): wheels = 4 def __init__(self,speed,type,name): self.speed = speed self.type = type self.name = name def print_car(self): print(name) print("-"*10) print("Speed: "+ speed) print("Type: "+ type) class lamborghini(Car): speed = "120Km/h" type = "Sports Car" name = "Lamborghini" print(lamborghini) I want to print Lamborghini atribbutes like this Lamborghini ---------- Speed: 120Km/h Type: Sports Car How do I do this in python?With just a print function
6 Answers
+ 1
https://code.sololearn.com/coDI8muRMXZ6/?ref=app
Here is the code as you want!
0
Try that :
class Lamborghini:
Car.__init__(self, "120km/h", "Sport Car", "Lamborghini")
car=Lamborghini()
car.print_car()
0
Sorry:
class Lamborghini(car) :
0
thank you can you explain why i have to write
Car.__init__(self, "120km/h", "Sport Car", "Lamborghini")
0
As creating new object Lamborghini, you also create a new object Car that allow you to print the attributes of the Lamborghini.
I don't really know how to explain better...
0
If you don't add that and try printing Lamborghini attributes, you'll have an error.