pythonTypeError: 'float' object cannot be interpreted as an integer

运行代码(python2)

number = 254 / thread_num

出现

TypeError: 'float' object cannot be interpreted as an integer  

原因:在python2,‘/’ 只留下了整数部分,去掉了小数,是int型。而在 python3里,‘/’ 的结果是真正意义上的除法,结果是float型。所以便出现了TypeError: ‘float’ object cannot be interpreted as an integer

将代码改为(python3)

number = 254 // thread_num

python2用‘/’,python3用‘//’

你可能感兴趣的:(pythonTypeError: 'float' object cannot be interpreted as an integer)