2015-06-25 60 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