1
Below is an example of using a function passed as a parameter to another function:
def gera_nums():
lista = []
for c in range(0, randint(1, 15)):
lista.append(randint(0, 100))
return lista
def extrai_maior(array):
print(f'Os números passados foram: {array}')
print(f'Foram passados {len(array)} números como parâmetro!')
print(f'O maior número passado foi o {max(array)}.')
extrai_maior(gera_nums())
Basically the first function generates a number x random (up to 14 numbers) of random numbers (between 0 and 99) and returns a list. This function is passed as parameter to the function extrai_maior
that analyzes the list and passes some information.
Considering that the first will only be used with the second, it’s pertinent to encapsulate the first within the second, right? What would that code look like? I’m not being able to apply it.
PS: The use of lambda in this case is impractical because it would not be possible to transform the first function into inline function, right?
Class! But I do not know if I understood the part of the developer, I am not properly initiated in this concept, although I have read about. Can you explain me in a synthetic way? I will search for content in parallel to exchange better. Thank you!
– Curi
@dev.Curi About decorators, you can start here: https://answall.com/q/23628/112052
– hkotsubo