Advertisement
Guest User

Untitled

a guest
Jul 24th, 2017
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.53 KB | None | 0 0
  1. """"
  2. Simple example of how to use a @property decorator
  3. """
  4.  
  5.  
  6. class Hellofy:
  7. def __init__(self, name, message):
  8. self.name = name
  9. self.message = message
  10.  
  11. @property
  12. def say_hello(self):
  13. return f"Hello {self.name}! {self.message}."
  14.  
  15. """
  16. In [1]: hellofy = Hellofy('Cintia', 'Have a nice day')
  17.  
  18. In [2]: hellofy.name
  19. Out[2]: 'Cintia'
  20.  
  21. In [3]: hellofy.message
  22. Out[3]: 'Have a nice day'
  23.  
  24. In [4]: # Now calling the say_hello() method as a property
  25.  
  26. In [5]: hellofy.say_hello
  27. Out[5]: 'Hello Cintia! Have a nice day.'
  28.  
  29. """
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement