【发布时间】:2017-08-01 08:55:08
【问题描述】:
print (1/3)
print (1./3)
我看不出 (1/3) 和 (1./3) 之间的区别。 我什么时候应该使用其中一种,为什么?
【问题讨论】:
-
请学习将代码 sn-ps 复制/粘贴为 文本,而不是图像...
-
在 Python 3.x 中,这与男性没有区别。在 Python 2.x 中,第一种形式将执行整数除法并评估为
0,这确实有所不同。 -
除了@brunodesthuilliers:您还应该考虑
/-division 和//-division 的不同输出。 -
hi @quốc-huy,
1/3将返回 0,因为它是python-2中的整数除法。使用1./3获取结果。Python3看不出区别。
标签: python python-2.7 python-3.x