In threading.thread, why does args take a comma at the end

Viewed 298

I am reading the multi-threading in python. When I come into code like below:

x = threading.Thread(target=thread_function, args=(1,))

I am a little bit confused why args is (1,) which takes a comma at the end. I have tested that if I remove the comma it won't work. But I kind of get confused what is the difference here.

1 Answers

The reason why your code doesn't work without the comma is that the args parameter must contain a tuple, and the common way of creating a single-element tuple is exactly like (elem,).

If you remove the comma, the python interpreter will just ignore the parentheses and pass 1 as argument.

Related