我不确定是否将其发布在 stackoverflow 或程序员上,如果我选错了,很抱歉。我对 python 也很陌生,所以我可能会遗漏一些东西。
其中哪一个更正确。如,哪一个是最佳实践。两者都有吗?如果是这样,我什么时候使用。
1) 拉姆达:
def hello_world():
server_thread = threading.Thread(target=lambda: print("Hello World"))
2)函数内部的函数
def hello_world():
def hello():
print("Hello World")
server_thread = threading.Thread(target=hello)