请教一个 Python 问题
資深大佬 : commoccoom 3
import threading def f(dicts): for key in dicts: print (key,dicts[key]) dict1 = {'a':'b','c':'d'} ta = threading.Thread(target=f,kwargs=dict1) ta.start()
为什么这里的f函数内无法使用for循环呢?
大佬有話說 (6)
import threading def f(dicts): for key in dicts: print (key,dicts[key]) dict1 = {'a':'b','c':'d'} ta = threading.Thread(target=f,kwargs=dict1) ta.start()
为什么这里的f函数内无法使用for循环呢?
写法 2:
ta = threading.Thread(target=f, kwargs={‘dicts’: dict1})
了解下 args / kwargs / 解包等概念。