Created
July 25, 2017 00:52
-
-
Save augustogoulart/8d76a62046255fe4ad87e55f7b3f7022 to your computer and use it in GitHub Desktop.
Simple example of how to use a @Property decorator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""" | |
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