Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # OOP: METHOD
- class Hero:
- # Class/ static variable
- amount_hero = 0
- # Constructor __init__()
- def __init__(self, inputName, inputHealth, inputPower, inputArmor):
- # Instance variable
- self.name = inputName
- self.health = inputHealth
- self.power = inputPower
- self.armor = inputArmor
- Hero.amount_hero += 1
- # Void function, method without argument & return value
- def who(self):
- print("My Name: ", self.name)
- # Method with argument & without return
- def healthUp(self, up):
- self.health += up
- # Method with return value
- def getHealth(self):
- return self.health
- hero1 = Hero("sniper", 100, 10, 4)
- hero2 = Hero("mario", 90, 15, 1)
- hero3 = Hero("ifa", 1000, 100, 0)
- print(hero1.__dict__)
- print(hero2.__dict__)
- print(hero3.__dict__)
- hero1.who()
- hero1.healthUp(11)
- print(hero1.health)
- print(hero1.getHealth())
- # Link: https://www.youtube.com/watch?v=DE-h_oR8Nmo&list=PLZS-MHyEIRo7ab0-EveSvf4CLdyOECMm0&index=4
Add Comment
Please, Sign In to add comment