Created
July 1, 2021 20:22
-
-
Save luizomf/95bd5fd4850b3ead4259af53d233a1dd to your computer and use it in GitHub Desktop.
Getters e setters - Reforço
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
# SETTER = CONFIGURANDO UM VALOR (=) | |
# GETTER = OBTER UM VALOR (.) | |
class Pessoa: | |
def __init__(self, nome): | |
self._nome = nome | |
@property | |
def nome(self): | |
return self._nome | |
@nome.setter | |
def nome(self, nome): | |
self._nome = nome | |
@property | |
def sobrenome(self): | |
return 'DESCONHECIDO' | |
p1 = Pessoa('Otávio') | |
print(p1.nome) | |
print(p1.sobrenome) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
SETTER = CONFIGURANDO UM VALOR (=)
GETTER = OBTER UM VALOR (.)
class Pessoa:
def init(self, nome):
self._nome = nome
p1 = Pessoa('Otávio')
print(p1.nome)
print(p1.sobrenome)