2015-06-25 64 views
3

我在学习Python时使用Sublime Text 2,实际上我只是一个初学者。现在,当我在编辑器中编写type(1/2)并构建它时(cmd + B),我得到的输出为int。相反,如果我在Sublime的终端(ctrl +`)中写入相同的指令,我得到的结果为float。有人可以解释我为什么会这样?Python类型()显示不同的结果

type(1/2) #in Sublime's editor results: <type 'int'> 
type(1/2) #in Sublime's python console results <type 'float'> 

我相信它应该是 “INT”,但仍然为什么是说 “浮动”。

回答

7

某处的代码是从__future__.division

>>> type(1/2) 
<type 'int'> 
>>> from __future__ import division 
>>> type(1/2) 
<type 'float'> 

python2.7进口

>>> type(1/2) 
<type 'int'> 

Python 3中有类型的报告此为一类,所以它不是使用python3解释。

python3

>>> type(1/2) 
<class 'float'> 
+0

谢谢你,这是有道理的。 – Greenhorn

+0

[如果这回答你的问题,请接受答案。](https://meta.stackexchange.com/questions/109956/is-it-important-to-say-thanks-after-getting-correct-answer) – AlexLordThorsen

+0

我只是等着看,如果我能得到任何其他解释这个问题的答案。任何如何,你回答我。 – Greenhorn