Skip to content

Commit

Permalink
Merge pull request mouredev#4532 from edalmava/python
Browse files Browse the repository at this point in the history
mouredev#24 - Python
  • Loading branch information
kontroldev authored Jun 25, 2024
2 parents 36b3d4c + 32c149f commit 1efecd1
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions Roadmap/24 - DECORADORES/python/edalmava.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
def decorador(funcion):
def wrapper(*a, **b):
print("La función no se ha llamado")
funcion(*a, **b)
print("La función ha sido llamada")
return
return wrapper

@decorador
def funcion(a, b):
pass

funcion(1, 2)

print("")
print("***RETO EXTRA***")
print("")

def contar(funcion):
def wrapper(*a):
wrapper.contador += 1
funcion(*a)
veces = 'vez' if wrapper.contador == 1 else 'veces'
print(f"La función ha sido llamada { wrapper.contador } { veces }")

wrapper.contador = 0
return wrapper

@contar
def sumar(a, b):
return a + b

sumar(1, 2)
sumar(3, 4)
sumar(5, 6)

0 comments on commit 1efecd1

Please sign in to comment.