Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

One way to accomplish this would be to use two separate threads, each running an infinite loop to print to the console, and use a library like threading to manage the threads. Here's an example:

import threading

def loop1():
    while True:
        print("Loop 1")

def loop2():
    while True:
        print("\t\t\t\t\tLoop 2")

# Start the two loops in separate threads
t1 = threading.Thread(target=loop1)
t2 = threading.Thread(target=loop2)
t1.start()
t2.start()

# Wait for the threads to finish
t1.join()
t2.join()

This code uses two functions, loop1 and loop2, each containing a while loop that prints to the console. The threading library is used to start and manage the two threads. The \t characters are used to add some spacing between the two loops on the console.