-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaula103.py
More file actions
27 lines (21 loc) · 748 Bytes
/
Copy pathaula103.py
File metadata and controls
27 lines (21 loc) · 748 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
"""
Funções decoradoras e decoradores
Decorar = Adicionar / Remover / Restringir / Modificar
Funções decoradoras são funções que decoram outras funções
Decoradores são usados para fazer o Python usar as funções decoradoras em outras funções
"""
def criar_funcao(func):
def interna(*args, **kwargs):
for arg in args:
is_string(arg)
resultado = func(*args, **kwargs)
return resultado
return interna
def inverte_string(string):
return string[::-1]
def is_string(param):
if not isinstance(param, str):
raise TypeError('param deve ser uma string')
invertida_string_check_param = criar_funcao(inverte_string)
invertida = invertida_string_check_param('123')
print(invertida)