多线程基础

 1 __author__ = 'anna'
 2 # encoding:utf-8
 3 
 4 
 5 import threading
 6 import time
 7 
 8 
 9 def music():
10     time.sleep(5)
11     print('打印方法音乐!')
12 
13 
14 def book(name):
15     time.sleep(5)
16     print(name)
17 
18 
19 t1 = threading.Thread(target=music)
20 # 这个地方必须是元组形式,后面需要加一个冒号,否则都会报错(尝试了下,写成字符串形式会报错!)
21 t2 = threading.Thread(target=book, args=('哇塞,天气不错哦!',))
22 
23 t1.start()
24 t2.start()

 

posted @ 2020-07-21 10:02  anna1210  阅读(83)  评论(0编辑  收藏  举报