TypeError:<<:' int'不支持的操作数类型并且'漂浮'

时间:2017-02-25 11:17:53

标签: python bitwise-operators

这个开源代码我试图玩跳棋,代码工作得很好,直到拍了一块,然后出现以下错误:

line 73, in make_move
    taken_piece = int(1 << sum(i for (i, b) in enumerate(bin(move)[::-1]) if b == '1')/2)
TypeError: unsupported operand type(s) for <<: 'int' and 'float'

有关如何解决此问题的任何帮助?

1 个答案:

答案 0 :(得分:3)

您不能通过浮点/小数移位位,错误很明显。 sum(...)/2在当前操作中给出一个浮点数。

然而,你可以做的是在Python 3中使用//执行整数除法。对于Python 2,/执行整数除法(对于int操作数),除非你重写了默认行为。

相关问题