Skip to content

Instantly share code, notes, and snippets.

@augustogoulart
Created July 25, 2017 00:52
Show Gist options
  • Save augustogoulart/8d76a62046255fe4ad87e55f7b3f7022 to your computer and use it in GitHub Desktop.
Save augustogoulart/8d76a62046255fe4ad87e55f7b3f7022 to your computer and use it in GitHub Desktop.
Simple example of how to use a @Property decorator
""""
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.'
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment