Advertisement
albin900

Classes

Jul 28th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.46 KB | None | 0 0
  1.  
  2. class Currency:
  3.     price = None # variables inside a class but outside of functions don't need self.
  4.     def __init__(self, name, volatile):
  5.         self.name = name
  6.         self.volatile = volatile
  7.        
  8.     def getPrice(self):
  9.         self.price = requests.get("https://albinapi.com/currency/"+self.name).text
  10.         return self.price
  11.        
  12.  
  13.  
  14. usd = Currency("usd", False)
  15. euro = Currency("sek", False)
  16. btc = Currency("btc",True)
  17.  
  18. print btc.getPrice()
  19.  
  20.  
  21. print euro.volatile # False
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement