Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """"
- Simple example of how to use a @property decorator
- """
- class Hellofy:
- def __init__(self, name, message):
- self.name = name
- self.message = message
- @property
- def say_hello(self):
- return f"Hello {self.name}! {self.message}."
- """
- In [1]: hellofy = Hellofy('Cintia', 'Have a nice day')
- In [2]: hellofy.name
- Out[2]: 'Cintia'
- In [3]: hellofy.message
- Out[3]: 'Have a nice day'
- In [4]: # Now calling the say_hello() method as a property
- In [5]: hellofy.say_hello
- Out[5]: 'Hello Cintia! Have a nice day.'
- """
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement