Python () type shows different results

I am using Sublime Text 2

, learning Python, in fact I am just a beginner. Now when I write type(1/2)

in the editor and build it ( cmd + B ) I get the output as int . Instead, if I write the same statement in Sublime terminal ( ctrl + ` ), I get the result as a float . Can someone explain to me why this is happening?

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

      

I believe it should be " int ", but still why does it say " float ".

+3


source to share


1 answer


Somewhere the code is imported from __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 has report this type as a class, so it is not an interpreter using python3.

python3

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

      

+7


source







All Articles