Advertisement
user_137

Untitled

Aug 25th, 2018
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.40 KB | None | 0 0
  1. >>> class F:
  2. ...     def __init__(self, cost, value):
  3. ...         self.cost = cost
  4. ...         self.value = value
  5. ...     def getValueDividedByCost(self):
  6. ...         return self.value / self.cost
  7.  
  8. >>> superfood = F(0.1, 1000)
  9.  
  10. >>> superfood.cost
  11. 0.1
  12.  
  13. >>> superfood.value  # so both of these are data attributes
  14. 1000
  15.  
  16. >>> superfood.getValueDividedByCost()  # this is calling a function (method)
  17. 10000.0
  18.  
  19. >>>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement