pythonTypeError: ‘float’ object cannot be interpreted as an integer

  • Post author:
  • Post category:python


运行代码(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用‘//’



版权声明:本文为qq_41239950原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。