lundi 10 janvier 2022

lambda function to random color

I want generate RGB color with Lambda function. I have tried to do this code:

r = lambda: random.randint(0,255)
color=[r,r,r]

print(r)
color

Output:

<function <lambda> at 0x7f2aca8a7c20>
  
  [<function __main__.<lambda>>,
   <function __main__.<lambda>>,
   <function __main__.<lambda>>] 

I did not even get one number (r). Can anyone explain to me why this function is not good?


Update and Edit:

I realized that the lambda is a function that receives no value r() But how do you make the paint work in the same method and not permanently

If it is possible to convert a variable to a random number - that will not be in the function. That is, whenever a variable is available it will be different?




Aucun commentaire:

Enregistrer un commentaire