Created
July 24, 2018 15:05
-
-
Save FeraruSilviuMarian/022735f7c4d4c25555b49e67f4fcfadb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Car: | |
numberOfCars = 0 | |
def __init__(self, color, brand, model): | |
self.color = color | |
self.brand = brand | |
self.model = model | |
self.engine = 'off' | |
Car.numberOfCars += 1 | |
def startEngine(self): | |
self.engine = 'on' | |
print('engine is now started') | |
def isEngineOn(self): | |
return self.engine == 'on' | |
myCar = Car('gray', 'volvo', 'cheapest model') | |
yourCar = Car('blue', 'tesla', 'x') | |
print(myCar.isEngineOn()) # False | |
print(myCar.color) # gray | |
print(yourCar.model) # x | |
# this is an example on how a class variable can | |
# be used to count how many objects of that class | |
# were instantiated (created) | |
print(Car.numberOfCars) # 2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment