import threading def my_func(): print("Hello from a thread") t = threading.Thread(target=my_func) t.start()
import threading def my_func(): print("Hello from a thread") t = threading.Thread(target=my_func) t.start() t.join() print("Thread is done")
import threading def my_func(name): print("Hello from", name) t = threading.Thread(target=my_func, args=("Alice",)) t.start()In this example, the Thread class takes an additional argument `args` that is a tuple of arguments to be passed to the target function. The message "Hello from Alice" will be printed when the thread is executed. Overall, the Python threading package library makes it easy to manage multiple threads in a program to run concurrently.