Advertisement
Guest User

Intro OOP

a guest
Mar 18th, 2019
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. # Please replace:
  2. class Car:
  3. # object initialization method
  4. # object initializer / constructor
  5. def __init__(car): #Everytime, you make an object this is called! Car()
  6. #init... the first argument, is a reference to the object itself.
  7. #typically called 'self' but not required
  8. car.name = 'Acura'
  9. car.brand = 'RSX'
  10. car.year = '2020'
  11. # print ("Hello, "+ "Tim's "+ car.name +"!")
  12. def getyear(self):
  13. return self.year
  14. def getname(self):
  15. return self.name
  16. def getbrand(self):
  17. return self.brand
  18.  
  19. # https://stackoverflow.com/questions/44726196/how-to-implement-multiple-constructors-in-python
  20. def main():
  21. # auto = Car()
  22. # Car() #Object initialization syntax - the class name + the argument list
  23. # Car()
  24. # Car()
  25. # print (Car().name)
  26. rsx = Car()
  27. print ('Tim has got a ' + rsx.getyear() + ' ' + rsx.getbrand() + ' ' + rsx.getname() + '!')
  28.  
  29. if __name__ == "__main__":
  30. main()
  31. # pass
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement