Advertisement
naren_paste

Threading_2&3

Aug 16th, 2023
808
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.45 KB | Source Code | 0 0
  1. import threading
  2.  
  3. def print_squares():
  4.     for i in range(1, 6):
  5.         print(f"Square of {i}: {i*i}")
  6.  
  7. def print_cubes():
  8.     for i in range(1, 6):
  9.         print(f"Cube of {i}: {i*i*i}")
  10.  
  11. if __name__ == "__main__":
  12.     thread1 = threading.Thread(target=print_squares)
  13.     thread2 = threading.Thread(target=print_cubes)
  14.  
  15.     thread1.start()
  16.     thread2.start()
  17.  
  18.     thread1.join()
  19.     thread2.join()
  20.  
  21.     print("Both threads have finished.")
  22.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement