120. Multithreading with Threading:
import threading
def print_hello():
print("Hello from thread!")
# Create a thread to run the function
thread = threading.Thread(target=print_hello)
thread.start()
thread.join() # Wait for the thread to finishimport threading
def print_number(number):
print(f"Number: {number}")
threads = []
for i in range(5):
thread = threading.Thread(target=print_number, args=(i,))
threads.append(thread)
thread.start()
# Wait for all threads to finish
for thread in threads:
thread.join()Last updated