TypeError: sequence index must be integer

TypeError: sequence index must be integer

我只是在每 3 个字符之间添加一个“,”时遇到了问题。

print totalpoints
points = ','.join([totalpoints[i:i+3] for i in range(0, totalpoints, 3)])

输出:

875
TypeError: sequence index must be integer

我不知道你到底想做什么。不过如果我没看错的话,下面的内容可以解决你的问题。

>>> totalpoints = 875123123 
>>> totalpoints = str(totalpoints)
>>> points = ','.join([totalpoints[i:i+3] for i in range(0, len(totalpoints), 3)])
>>> points
'875,123,123'