1

In python I know we can define function in below 2 ways,

def show():
    print("hi")

and using lambda

show=lambda x: print(x)
show("hi")

Is there any performance advantage ever notice in one over the other.? especially in programs that involve large computations.

I tried timed programs and comparing its execution durations. but did not notice any difference. I need to know if this is the case, especially in industry grade applications.

John mason
  • 21
  • 2
  • 1
    As far as I know, I see no difference at all in execution. – Liju Jan 16 '23 at 14:02
  • 1
    lambda are just available for convenience (kind of syntactic sugar). Shorter ways to describe things are not always faster. In fact, it is often quite the opposite unfortunately. If you need speed, consider not using the slow CPython *interpreter* (or even a native language like C/C++). Alternatively, you can use tools generating fast native binary code like Cython or Numba. – Jérôme Richard Jan 16 '23 at 14:40

0 Answers0