-1

I want to understand what self means in the lambda function.

In the Locust tool I found this code :

import random

class WebsiteUser(HttpLocust):
    task_set = UserBehaviour
    wait_function = lambda self: random.expovariate(1)*1000

Can anyone explain what self means in the lambda function? Or in short what is happening in this lambda function?

kenlukas
  • 3,221
  • 9
  • 23
  • 35

1 Answers1

0

Your definition is equivalent to

class WebsiteUser(HttpLocust):
    task_set = UserBehaviour
    def wait_function(self):
        return random.expovariate(1)*1000

self is the conventional name for the first argument to an instance method, whether you use a def statement or a lambda expression to define the method.

chepner
  • 446,329
  • 63
  • 468
  • 610