Skip to content

Instantly share code, notes, and snippets.

@FeraruSilviuMarian
Created July 24, 2018 15:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FeraruSilviuMarian/022735f7c4d4c25555b49e67f4fcfadb to your computer and use it in GitHub Desktop.
Save FeraruSilviuMarian/022735f7c4d4c25555b49e67f4fcfadb to your computer and use it in GitHub Desktop.
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