Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Human:
- # this is a static attribute/fiel
- numberOfHumans = 0
- ## dunder abbreviation for double underscore
- # similar to object constructor in JS, but __init__ is ran
- # when object is instantiated
- def __init__(self, name, age):
- self.name = name
- self.age = age
- Human.numberOfHumans += 1
- # object method used for instantiated objects based off
- # Human Class's template
- def sayName(self):
- print(self.name)
- # if a method in a class does not require the use
- # `self` then it is a static method
- @staticmethod
- def addNumsStatic(x, y):
- return x + y
- # private method to the class ONLY by the double-underscore (dunder)
- # good for use inside of class
- def __AddNumsPrivate(self, x, y):
- return self + x + y
Add Comment
Please, Sign In to add comment