Create Thread without Inheritance in Python
Master Python with 70+ Hands-on Projects and Get Job-ready - Learn Python
Program 1
import time
from threading import *
class MyThread:
def display(self,n):
print(current_thread().getName())
for i in range(1,n+1):
print(i)
time.sleep(1)
# Main Thread
M1=MyThread()
T1=Thread(target=M1.display,args=(5,),name="First")
T2=Thread(target=M1.display,args=(10,),name="Second")
T1.start()
T2.start()
Did we exceed your expectations?
If Yes, share your valuable feedback on Google

