rangga_hrdme

constructor __init__()

Apr 9th, 2021 (edited)
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.77 KB | None | 0 0
  1. # Object Oriented Programming (OOP)
  2. # Main class
  3. class Hero:
  4.     # Class/ static variable
  5.     amount = 0
  6.  
  7.     # Constructor __init__()
  8.     def __init__(self, inputName, inputHealth, inputPower, inputArmor):
  9.         # Instance variable
  10.         self.name    = inputName
  11.         self.health  = inputHealth
  12.         self.power   = inputPower
  13.         self.armor   = inputArmor
  14.  
  15. hero1 = Hero("sniper", 100, 10, 4)
  16. hero2 = Hero("mirana", 100, 15, 1)
  17. hero3 = Hero("ucup", 1000, 100, 0)
  18.  
  19.  
  20. print(hero1.name)
  21. print(hero2.health)
  22. print(hero3.armor)
  23.  
  24. # Show All Atribute: Dictionary
  25. print(hero1.__dict__); print(hero2.__dict__); print(hero3.__dict__)
  26. print(Hero.__dict__)
  27.  
  28. # Link: https://www.youtube.com/watch?v=w9emRmkbeps&list=PLZS-MHyEIRo7ab0-EveSvf4CLdyOECMm0&index=2
Add Comment
Please, Sign In to add comment