-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,616
  • 9
  • 25
  • 36

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
  • 497,756
  • 71
  • 530
  • 681