文章会有【原创】或者【转载】标示,部分来自Google Baidu的学习结果 {Java/PHP/Python/Ruby/Go}

Python 多线程学习  


#-*- coding: UTF-8 -*-
#author PHPer.yang@gmail.com
import threading

#方法一
def sayHello(name):
    print("Hello,I'm Thread-%s"% (name))

for i in range(4):
    t = threading.Thread(target=sayHello,args=(i+1,))
    t.start()

#方法二
class ThreadClass(threading.Thread):
    def run(self):
        er = self.getName()
        print("Hello,I'm %s"%er)

for i in range(4):
    t = ThreadClass()
    t.start()