.Thread() method is a class constructor which returns a thread object that can run a function with zero or more arguments.
Functions are commonly passed as the
target argument, but without parentheses. If any items are listed in the
args tuple, they are passed as positional arguments to the
The object that returns from the
.Thread() constructor can be assigned to its own variable, as shown in the example below:
import threadingthread_1 = threading.Thread()thread_2 = threading.Thread()print(thread_1)print(thread_2)
Every thread object has a
name attribute that, unless otherwise specified, defaults to
<Thread(Thread-1, initial)><Thread(Thread-2, initial)>
In the example below, a thread,
hello_thread, targets the
say_hello() function with supplied arguments. After the thread is created, the targeted
say_hello() function is executed when the
.start() method is run.
Interested in helping build Docs? Read the Contribution Guide or share your thoughts in this feedback form.
Learn Python on Codecademy
Computer ScienceLooking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
Includes 6 Courses
With Professional Certification