w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Executing code in parallel with python

Try this:

thr.append(threading.Thread(target=square, args=(k,)))

instead of thr.append(threading.Thread(target=square(k)))

You get that error because you end up calling the function in your code. When the function is called, square(k) returns an int which is not callable.

Refer to the documentation.

Also, as unutbu has pointed out in the comments to the question, you are doing an XOR and not computing the square. Squares are computed this way: x**2 and not x^2.

Also, you are returning the result before adding it to the list, so you might want to reverse the order of the two lines in your function definition if you want to add the square of the number to the list, result.

© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.