print的时候报错:TypeError: unsupported operand type(s) for /: 'str' and 'int'

  统计/机器学习 Python    浏览次数:5366        分享
0

python里用print的时候报错

seconds = 100
print('Total time: %.1f minutes'%seconds/60)

完全不明白为什么出错了,错误信息是

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

R琳   2019-09-10 14:48



   1个回答 
2

你上面报错信息是说你用字符串和整数做了除法,自然就报错了。

你在seconds/60的周围少了一对括号,应该是

print('Total time: %.1f minutes'%(seconds/60))
SofaSofa数据科学社区DS面试题库 DS面经

宽宽   2019-09-10 15:05

啊,多谢~我都没注意到是因为括号! - R琳   2019-09-13 14:57


  相关讨论

print(__doc__)有什么用?

python里print时出现ValueError: unsupported format character 错误

print里的"%.2f"是什么意思?

怎么print或者查看tf.tensor中的数值

pyton两个dict如何合并?如果key有重复,取最小值

python里的continue是什么意思

python如何判断某路径下是否存在指定的csv文件?

如何对将Python dictionary里的key按照value进行排序?

怎么对有多个空格的字符串进行split?

东方财富的数据怎么爬下来

  随便看看

特征归一化对K Means有影响吗?

为什么机器学习中的优化问题很少用到牛顿法?

PCA降维之前为什么要先标准化?

什么是SMOTE sampling方法?

pandas读取csv中指定的某些列