Class atribbutes printing | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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

15th Aug 2018, 9:49 PM
BananasDZN sd
BananasDZN sd - avatar
6 Answers
+ 1
15th Aug 2018, 10:32 PM
Théophile
Théophile - avatar
0
Try that : class Lamborghini: Car.__init__(self, "120km/h", "Sport Car", "Lamborghini") car=Lamborghini() car.print_car()
15th Aug 2018, 10:25 PM
Théophile
Théophile - avatar
0
Sorry: class Lamborghini(car) :
15th Aug 2018, 10:25 PM
Théophile
Théophile - avatar
0
thank you can you explain why i have to write Car.__init__(self, "120km/h", "Sport Car", "Lamborghini")
15th Aug 2018, 10:35 PM
BananasDZN sd
BananasDZN sd - avatar
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...
15th Aug 2018, 10:39 PM
Théophile
Théophile - avatar
0
If you don't add that and try printing Lamborghini attributes, you'll have an error.
15th Aug 2018, 10:40 PM
Théophile
Théophile - avatar