Python programming 2: Object Oriented Programming

python

Python is a hight level programming language that supports Object Oriented Programming. The concepts one should be familiar is Class, Objects and instances, methods or functions, etc. Thus tutorial is aimed to introduce OOP using Python to audience that are already familiar with these concepts using any other OOP language such as Java, C++, etc

=======
#!/usr/bin/python

class MyVehicle:
          “””The __init__ function the the constructor of the class”””
          def __init__(self, theBrand, theModel): #The “self” variable is needed by default even if there are no variables to be passed.
                    self.theBrand = theBrand
                    self.theModel = theModel

          def speed(self, mySpeed):
                    print(“My ” + self.theBrand + ” ” + self.theModel + ” can go at a speed of ” + str(mySpeed))

          def theType(self, theType):
                    print(“I am of the type ” + str(theType))
def main():
          myCar = MyVehicle(‘Honda’, ‘Accord’)
          myCar.speed(’60 kmh’)

          myNextCar = MyVehicle(‘Jeep’, ‘Wrangler’)
          myNextCar.speed(’40 kmh’)

main()
=======