diff --git a/Basic/Basic_Of_Python/src/thread.py b/Basic/Basic_Of_Python/src/thread.py new file mode 100644 index 0000000..0798511 --- /dev/null +++ b/Basic/Basic_Of_Python/src/thread.py @@ -0,0 +1,28 @@ +import threading +import time + +# Function that will be executed by the first thread +def print_numbers(): + for i in range(1, 6): + print(f"Number: {i}") + time.sleep(1) # Simulate a time-consuming task + +# Function that will be executed by the second thread +def print_letters(): + for letter in ['A', 'B', 'C', 'D', 'E']: + print(f"Letter: {letter}") + time.sleep(1) # Simulate a time-consuming task + +# Create two threads +thread1 = threading.Thread(target=print_numbers) +thread2 = threading.Thread(target=print_letters) + +# Start the threads +thread1.start() +thread2.start() + +# Wait for both threads to complete +thread1.join() +thread2.join() + +print("Both threads have finished execution.")