Code Explanation:
1. Importing the Module
import threading
๐ Explanation:
Imports Python’s built-in threading module
This module allows you to run multiple functions concurrently
๐ 2. Defining the Task Function
def task():
print("A")
๐ Explanation:
A function named task is created
It simply prints "A"
This function will run inside a separate thread
๐ 3. Creating a Thread
t = threading.Thread(target=task)
๐ Explanation:
Creates a new thread object t
target=task means:
๐ “Run the task function inside this thread”
๐ 4. Starting the Thread
t.start()
๐ Explanation:
Starts the thread execution
The task() function begins running in parallel
Now:
Main program continues
Thread runs independently
๐ 5. Main Thread Execution
print("B")
๐ Explanation:
This runs in the main thread
Prints "B"
Possible outputs:
A
B

0 Comments:
Post a Comment