Published on January 26, 2024By DeveloperBreeze
import threading
# Function to print numbers
def print_numbers():
for i in range(1, 6):
print('Number:', i)
# Function to print letters
def print_letters():
for letter in 'abcde':
print('Letter:', letter)
# Create threads for each function
t1 = threading.Thread(target=print_numbers)
t2 = threading.Thread(target=print_letters)
# Start both threads concurrently
t1.start()
t2.start()
# Wait for both threads to complete
t1.join()
t2.join()
Comments
Please log in to leave a comment.