SHARE
TWEET

Untitled

a guest Feb 18th, 2019 73 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Human:
  2.  
  3.     # this is a static attribute/fiel
  4.     numberOfHumans = 0
  5.  
  6.     ## dunder abbreviation for double underscore
  7.     # similar to object constructor in JS, but __init__ is ran
  8.     # when object is instantiated
  9.     def __init__(self, name, age):
  10.         self.name = name
  11.         self.age = age
  12.         Human.numberOfHumans += 1
  13.  
  14.     # object method used for instantiated objects based off
  15.     # Human Class's template
  16.     def sayName(self):
  17.         print(self.name)
  18.  
  19.     # if a method in a class does not require the use
  20.     # `self` then it is a static method
  21.     @staticmethod
  22.     def addNumsStatic(x, y):
  23.         return x + y
  24.  
  25.     # private method to the class ONLY by the double-underscore (dunder)
  26.     # good for use inside of class
  27.     def __AddNumsPrivate(self, x, y):
  28.         return self + x + y
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top