Using function inside function instead of lambda

I was not sure whether to post this to stackoverflow or programmers, so sorry if I chose the wrong one. I am also very new to python, so there might be something missing for me.

Which one is more correct. As in, which one is best practice. Both? If so, which one do I use when.

1) Lambda:

def hello_world(): server_thread = threading.Thread(target=lambda: print("Hello World")) 

2) Function inside function

 def hello_world(): def hello(): print("Hello World") server_thread = threading.Thread(target=hello) 
+4
source share
1 answer

Both are absolutely acceptable.

Just keep in mind that a nested function can turn into something more complex, while a lambda is forever limited to one expression.

+1
source

Source: https://habr.com/ru/post/1485324/


All Articles