import threadingimport time# 定义一个变量nums = [11, 22]def test1(nums): nums.append(33) print('-----------in test1 num={}---'.format(nums))def test2(): print('-----------in test2 num={}---'.format(nums))def main(): t1 = threading.Thread(target=test1, args=(nums,)) # args 传递参数,要用元组的形式 t2 = threading.Thread(target=test2) t1.start() time.sleep(1) t2.start() time.sleep(1) print('-----------in main Thread num={}---'.format(nums))if __name__ == '__main__': main()
来源:https://www.cnblogs.com/fuyouqiang/p/11770320.html