File tree Expand file tree Collapse file tree 1 file changed +36
-0
lines changed
Roadmap/24 - DECORADORES/python Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Original file line number Diff line number Diff line change 1+ def decorador (func ):
2+ def opp (a , b ):
3+ print (f'llamada a la funcion { func .__name__ } ' )
4+ resultado = func (a , b )
5+ return '' .join ([f'Resultado de la funcion { func .__name__ } : ' , str (resultado )])
6+ return opp
7+
8+ @decorador
9+ def suma (a ,b ):
10+ return a + b
11+
12+ @decorador
13+ def resta (a ,b ):
14+ return a - b
15+
16+ print (suma (5 , 5 ))
17+ print (resta (5 , 5 ))
18+
19+
20+ '''
21+ EXTRA
22+ '''
23+ def contador_de_llamada (func ):
24+ func .contador = 0
25+ def counter ():
26+ func .contador += 1
27+ print (f'Se ha llamado { func .contador } veces a la funcion { func .__name__ } ' )
28+ return func
29+ return counter
30+
31+ @contador_de_llamada
32+ def llamar_funcion ():
33+ print ()
34+
35+ llamar_funcion ()
36+ llamar_funcion ()
You can’t perform that action at this time.
0 commit comments