class Car(object): condition = "new" def __init__(self, model, color, mpg): self.model = model self.color = color self.mpg = mpg def display_car(self): print "This is a " + self.color + " " + self.model + " with " + str(self.mpg) + " MPG." def drive_car(self): self.condition = "used" class ElectricCar(Car): batery = "molten salt" def __init__(self, model, color, mpg): Car.__init__(self, model, color, mpg) def drive_car(self): self.condition = "like new" my_car = Car("DeLorean", "silver", 88) my_car = ElectricCar("Chevrolet Nova", "Cottonwood Green", 75) print my_car.condition + " new" my_car.drive_car() print my_car.condition + " used" print my_car.batery
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question