Python考试题--第66道题目--当运行一个进程函数时,怎样为该函数传送参数--2022年04月21日
原创目录
1.解决问题的思路:
1,导入线程库:threading
2,创建线程函数func1
3,创建一个作为条目的函数。
4,启动线程函数
2.示例代码演示:
# 导入线程的库。
import threading
# 创建线程函数func1
def func1(s, fun): # 参数是字符串、函数
print(正在执行的功能func1)
fun(s) # 调用传入函数,相当于函数自增。
def ff (s):
print(f"ff输出字符串{s}")
tt1 = threading.Thread(target=func1, args=("hello world",ff))
tt1.start()
3.摘要:
1,可以通过Thread类的args参数传递线程函数的参数值。
2、hello world 相当于回调函数的输出字符串。
版权声明
所有资源都来源于爬虫采集,如有侵权请联系我们,我们将立即删除
itfan123





