Created
July 8, 2017 15:50
-
-
Save marcoscastro/cd242de4778471322259b810a5c370ed to your computer and use it in GitHub Desktop.
Exemplo simples de decorator em 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
def maiuscula(funcao): | |
def wrapper(texto): # função que modifica | |
return funcao(texto.upper()) # transforma pra maiúscula | |
return wrapper # retorna a função modificadora | |
@maiuscula | |
def imprimir_mensagem(nome): | |
print('Bem-vindo(a) %s' % nome) | |
imprimir_mensagem('marcos') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment