Python - 除法和浮点数

时间:2016-06-07 13:49:12

标签: python

根据这里的Python教程https://docs.python.org/3/tutorial/introduction.html

这给出了一个浮点数:

>>> 17 / 3  # classic division returns a float
5.666666666666667

然而,当我尝试它时,我得到:

>>> 17 / 3
5

为什么? FWIW,我在Mac上使用Python 2.7.10

2 个答案:

答案 0 :(得分:1)

Python 2.7和3之间的行为发生了变化。

答案 1 :(得分:1)

答案在URL中:

https://docs.python.org/3/tutorial/introduction.html
https://docs.python.org/2.7/tutorial/introduction.html

您发布的URL适用于Python 3,但您使用的是Python 2.7。

页面顶部有一个下拉列表。您可以从那里选择2.7以获取Python 2.7的文档:

>>> 17 / 3  # int / int -> int
5
相关问题