Created
September 29, 2021 14:04
-
-
Save VerosK/70fd58ec8d4d6e4e106933b253027c07 to your computer and use it in GitHub Desktop.
getters and setters python
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
class Pejsek: | |
def __init__(self, jmeno="Bobika"): | |
self.__jmeno = jmeno | |
def stekej(self): | |
print('{}: haf'.format(self.__jmeno)) | |
def __str__(self): | |
return f'<Pejsek name="{self.__jmeno}" at {id(self):x} - str>' | |
@property | |
def jmeno(self): | |
print("... getter called") | |
return self.__jmeno | |
@jmeno.setter | |
def jmeno(self, value): | |
print("... setter called") | |
self.__jmeno = value.capitalize() | |
if __name__ == '__main__': | |
alik = Pejsek("alik") | |
alik.jmeno = 'gulas' | |
print(alik) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment