为什么Jupyter显示的浮点值不同于Python控制台?
当我在Jupyter 4.3.1(Python 2.7.13)中运行以下代码时 我得到了以下输出为什么Jupyter显示的浮点值不同于Python控制台?,python,floating-point,jupyter-notebook,Python,Floating Point,Jupyter Notebook,当我在Jupyter 4.3.1(Python 2.7.13)中运行以下代码时 我得到了以下输出 5.0 5.1 5.199999999999999 5.299999999999999 5.399999999999999 5.499999999999998 5.599999999999998 5.6999999999999975 5.799999999999997 5.899999999999997 5.0 5.1 5.2 5.3 5.4 5.5 5.6 5.7 5.8 5.9 然而,当我在
5.0
5.1
5.199999999999999
5.299999999999999
5.399999999999999
5.499999999999998
5.599999999999998
5.6999999999999975
5.799999999999997
5.899999999999997
5.0
5.1
5.2
5.3
5.4
5.5
5.6
5.7
5.8
5.9
然而,当我在控制台中运行代码时,我得到了以下输出
5.0
5.1
5.199999999999999
5.299999999999999
5.399999999999999
5.499999999999998
5.599999999999998
5.6999999999999975
5.799999999999997
5.899999999999997
5.0
5.1
5.2
5.3
5.4
5.5
5.6
5.7
5.8
5.9
为什么Jupyter输出与控制台输出不同?
0.1
中的代码不完全是0。1@ThierryLathuille,我编辑了这个问题,由于某种原因,控制台和jupyterI中的输出不同,我不知道您使用的是什么“控制台”。在使用Python3.6的REPL中,我得到了与使用Jupyter完全相同的结果。您的控制台将打印数字的四舍五入值。@Thierrylahuille:问题指定了Python 2.7.13。当我尝试使用2.7.10时,会得到“控制台”输出的输出。@com请将print
行更改为:print type(I)、str(I)、repr(I)
,并显示两种环境的结果。