TypeError: unsupported operand type(s) for +: 'int' and 'str'

I have the Following:

labels_test = []
if label_type == 'neg':
labels_test.append('0')
else:
labels_test.append('1')

sum(labels_test)

I am getting this error:

---------------------------------------------------------------------------TypeError                                 Traceback (most recent call last)<ipython-input-15-d25fa4f7e23f> in <module>()----> 1 sum(labels_test)TypeError: unsupported operand type(s) for +: 'int' and 'str'

Solution:

You’re trying to sum  strings , which is incorrect. Change your Code like this:

labels_test = []
if label_type == 'neg':
labels_test.append(0)
else:
labels_test.append(1)
sum(labels_test)